[英]AJAX request not sending validate() data
我想在上面的PHP代码中接收validate函数的输出。 除了我的AJAX,其他所有东西都在工作。 谁能帮我解决问题?
$(document).ready(function(){
$("#d").click(function(){
validate();
})
function validate() {
var x;
var text;
var y, senddata;
x = document.getElementById('t').value;
y = x.length;
if (isNaN(x) || y < 10 || y > 10) {
document.getElementById('t').style.backgroundColor = "red";
}
// start AJAX in else case to receive validate data
else {
$.ajax({
url: 'json.php',
type: "POST",
dataType:'json',
data: ({ phone: x }),
success: function(response){
alert ("success !");
},
error: function(response){
alert("fail!");
}
});
}
}
});
需要在配置中进行更改以设置CORS调用的标志...
<httpProtocol>
<customHeaders>
<!-- Enable Cross Domain AJAX calls -->
<remove name="Access-Control-Allow-Origin" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
另外,为使AJAX正常工作,请更改条件以进入“其他”部分
借助js方法中的.action而不使用ajax完成
function datasend(send1,send2)
{
senddata=send1+send2;
document.forms["reg"].action="ajax.php?"+senddata;
//document.forms["reg"].submit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.