簡體   English   中英

數據沒有從ajax post方法傳遞到php回調

[英]data not passing from ajax post method to php call back

我正在嘗試在textarea中傳遞數據,並使php回調以retutn相同,並在進行簡單操作以確保傳輸后在textarea中顯示它。但是我無法使我的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+ textarea字段內的Data : Data sent from php call back to ajax function+ ,這意味着盡管正在進行通信,但是php回調無法讀取ajax調用者發送的數據,或者可能是ajax函數無法執行發送數據到php回調。

這是什么錯誤?

更換電線

ajaxVar.send(user_notes);

通過

ajaxVar.send('user_notes='+user_notes);

閱讀此http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM