[英]unable to send ajax request on php
我正在使用在php上发送ajax请求。 在表单方法中,im使用以下代码。
rohit1.php
<form action="index1.php" onsubmit="callfunc()">
<span id="raj"></span>
<input type="submit" value="submit"></div>
</FORM>
在javascript中,我使用:callfun.js
function callfunc()
{
var http =new XMLHttpRequest();
var name=prompt('enter name of the form');
var name="rohit";
var url = "index1.php";
var s = document.getElementById('raj').innerHTML;
alert(http);
http.open("POST", "index1.php?name="+name, true);
http.onreadystatechange = function()
{
if(http.readyState == 4 && http.status == 200)
{
}
}
http.send();
}
当我使用此功能时。 然后在提交时这是在index.php?label =而不是index.php?name =上重定向的?
只需尝试在callfunc()
函数的末尾添加return false
callfunc()
。 它将阻止表单的默认事件,并且不会充当标准表单。
<form action="index1.php" onsubmit="callfunc()">
<span id="raj"></span>
<input type="submit" value="submit"></div>
</form>
相应的javascript如下所示:
function callfunc() {
var name = "some name here"; // get this name from whereever you want
window.location.href = "index1.php?name="+name;
return false;
}
这应该为你工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.