将表单数据发布到php而不刷新页面

问题描述:

我正在尝试将表单数据发布到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.*.com/questions/271055/ –

+0

你是否用''关闭了窗体?看看你的开发者控制台。这里也没有PHP。 –

+0

'onclick =“posttophp”'不做任何事情;你需要添加括号来调用'posttophp()'“函数”。 –

两个想法尝试:

  1. 也许脚本应该调用函数之前放置,但不知道这件事。
  2. 尝试onclick="posttophp();"