请帮帮我,如何在按钮上使用两个ajax字段验证(如果数据已经存在,不要点击按钮或重定向同一页面)重定向停止?
这是我的ajax代码:
function validate()
{
return (chkunm() && chkemail());
}
function chkunm()
{
// alert ("hello");
var unm, http;
unm = document.getElementById("pupilname").value;
http= new XMLHttpRequest();
http.onreadystatechange=function(){
if (http.readyState==4 && http.status==200){
document.getElementById("s1").innerHTML=http.responseText;
}
if(http.responseText==true)
{
// alert ("Welcome");
return true;
}
else
{
// alert ("username already exists");
return false;
}
}
http.open("GET","getunm.php?unm="+unm,true);
http.send();
}
function chkemail()
{
// alert("hello");
// die();
var email, http;
email = document.getElementById("pupilpass").value;
http= new XMLHttpRequest();
http.onreadystatechange=function(){
if (http.readyState==4 && http.status==200){
document.getElementById("s2").innerHTML=http.responseText;
if(http.responseText==true)
{
// alert ("welcome");
return true;
}
else
{
//alert ("email already exists");
return false;
}
}
}
http.open("GET","getemail.php?email="+email,true);
http.send();
}
我想,如果数据已经存在...... !!所以不要点击按钮..怎么可能..帮助我
由于
答案 0 :(得分:0)
This回答可能对您有所帮助:
基本上你会有多个ajax调用来恢复他们的检查结果。在检查是否要重定向之前,您将使用$(document).ready(function(){
var check1, check2;
$("yourElement(s)").click(function(){
$.when(ajax1(), ajax2()) {
if(check1 || check2) {
// window.location - whatever your soul desires
}
}
}
function ajax1() {
return $.ajax({
url: "someUrl",
dataType: "json",
data: yourJsonData,
// whatever else you need,
success: function(result){
check1 = result;
}
});
}
// idem ajax 2 to get check2 value.
}
等待两者。
代码:
ThreadPool.QueueUserWorkItem((o) =>
{
FbEventClass.CreateEventController(cc);
});
正如您可能已经猜到的,此代码尚未经过充分测试。
我希望这会有所帮助。