2013-07-31 2 views
0

양식을 제출하고 Ajax를 사용하여 응답을 보내려고하지만 양식을 제출할 때 입력 한 값으로 새 창이 열립니다
기능이 작동하고Ajax 게시물을 제출하면 새 창이 열림

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link href="chat_style.css" rel="stylesheet" type="text/css"> 
</head> 
<body> 
<div id = "refresh" class="refresh"></div> 
<form method="POST" action="save.php" name="chat_send" onsubmit="sendChatData(); return false;"> 
    <input id="sender" name="sender" type="hidden" value ="<?php echo $sender ?>"> 
    <?php echo "$sender:" ?> <input name="texta" type="text" id="texta"/> 
    <input name="submit" type="submit" value="Send" /> 
</form> 

그리고 JS 코드 :

function sendChatData() { 

    var xmlHttpReq = false; 
    var self = this; 
    if (window.XMLHttpRequest) { 
     self.xmlHttpReq = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) { 
     self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 

    self.xmlHttpReq.open('POST', 'save.php' , true); 
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    self.xmlHttpReq.onreadystatechange = function() { 
     document.getElementById("texta").innerHTML = ""; 
     if (self.xmlHttpReq.readyState == 4) { 
      var x = self.xmlHttpReq.responseText; 
     } 
    } 
    self.xmlHttpReq.send(getquerystring()); 
} 

function getquerystring() { 
    var qstr = "message="; 
    try { 
     qstr += document.getElementById("texta").value; 
     window.open(qstr); 
    } catch (e) { 
     // empty... 
    } 
    return qstr; 
} 
그것은, 그것은 여기에 문제
인 HTML 코드 단지 새로운 창의한다

답변

3

코드에서 window.open으로 전화가 왔습니다. 그것은 - 새로운 (브라우저) 창을 엽니 다!

function getquerystring() { 
    var qstr = "message="; 
    try { 
     qstr += document.getElementById("texta").value; 
     window.open(qstr); // <-- Does exactly that - opens a new window! 
    } catch (e) { 
     // empty... 
    } 
    return qstr; 
} 
+0

OMG! 고마워요. 그 바보 같았다 니. – SagiLow

관련 문제