2017-04-02 74 views
-1

我正在嘗試將表單數據發佈到php文件而不刷新頁面。我正在使用似乎沒有工作的ajax。下面是表單語法和ajax。有人能幫幫我嗎?謝謝。將表單數據發佈到php而不刷新頁面

<form name="postcontent" id="postcontent"> 
function[]; //just for an example of data 
<button type="button" id="submitform" onclick="posttophp" >Send</button> 

<script> 
function posttophp() { 
    var xhttp = new XMLHttpRequest(); 
    xhttp1.onreadystatechange = function() { 
    if (this.readyState == 4 && this.status == 200) { 
     document.getElementById("submitform").innerHTML = this.responseText; 
    } 
    }; 
    xhttp.open("POST", "options.php", true); 
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
    xhttp.send(" 
function_Options1[]=function[]") 
} 
</script> 

在php中,我將function_Options1 []存儲在另一個變量中並進一步使用。

+0

使用瀏覽器的調試器,看看是否正在發送的Ajax和收到的響應。閱讀本文可能會有所幫助。 https://meta.stackoverflow.com/questions/271055/ –

+0

你是否用''關閉了窗體?看看你的開發者控制檯。這裏也沒有PHP。 –

+0

'onclick =「posttophp」'不做任何事情;你需要添加括號來調用'posttophp()'「函數」。 –

回答

0

兩個想法嘗試:

  1. 也許腳本應該調用函數之前放置,但不知道這件事。
  2. 嘗試onclick="posttophp();"
相關問題