我试图在文本区中传递数据,并使php回调返回相同的数据,并在简单的操作后显示在文本区中,以确保传输带place.But我不能让我的ajax函数传递数据。
<script type="text/javascript" src="ajax.js"></script>这是我的表格
<form action="#" method="post" onsubmit="submit_notes_call();return false;">
<textarea rows="5" cols="30" name="user_notes" id="user_notes"></textarea>
<input type="submit" name="notes_submit" id="notes_submit" value="UPDATE NOTES" >
</form>下面是我在ajax.js中的Ajax函数
function submit_notes_call()
{
var ajaxVar;
var user_notes = " Data from ajax call to php callback ";
/*document.getElementById("user_notes").value; */
try
{
ajaxVar = new XMLHttpRequest();
}catch (e)
{
try
{
ajaxVar = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e)
{
try
{
ajaxVar = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e)
{
alert("Your browser broke!");
return false;
}
}
}
ajaxVar.onreadystatechange=function(){
if(ajaxVar.readyState==4)
{
document.getElementById("user_notes").innerHTML = ajaxVar.responseText;
}
};
ajaxVar.open('POST','notes_submit.php',true);
ajaxVar.send(user_notes);
}下面是我用notes_submit.php编写的php代码
<?php
$data_recieved = "Data from php call back to ajax function+".$_POST['user_notes'];
echo "Data : " . $data_recieved;
?>我在文本区域字段中得到的输出为Data : Data sent from php call back to ajax function+,这意味着虽然正在进行通信,但是php回调无法读取ajax调用者发送的数据,或者ajax函数无法将数据发送到php回调。
这里的错误是什么?
发布于 2013-07-12 13:53:00
替换此行
ajaxVar.send(user_notes);通过
ajaxVar.send('user_notes='+user_notes);阅读此http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
https://stackoverflow.com/questions/17608193
复制相似问题