[英]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.