在2个不同的文本输入上使用ajaxStart&ajaxStop时发生冲突

问题描述:

我被ajaxStart/ajaxSend及其最终方法卡住了一点。我有2个不同的AJAX调用使用jQuery.post在2个文本输入上运行。第一个是从我的数据库中获取特定名称列表,并且我使用ajaxStart/ajaxStop来显示和隐藏微调器。这工作正常。下一个AJAX调用,用于检查电子邮件状态,再次在我的数据库中。我再次使用ajaxStart/ajaxStop以显示一个包含进程正在进行的消息的div,然后在该进程完成之后。 现在,我的问题是,当我输入第一个文本输入时,第二个输入的ajaxStart被调用,并且我可以看到div!我尝试使用ajaxSend和ajaxComplete,但没有运气!在2个不同的文本输入上使用ajaxStart&ajaxStop时发生冲突

代码:

//First request 
jQuery('.company-name input').keyup(function(event){ 
    //get the alphabets and post them using jQuery.post. 
}); 

jQuery('.company-name input').ajaxStart(function(){ 
    //Show the spinner 
}); 
jQuery('.company-name input').ajaxStop(function(){ 
    //hide the spinner 
}); 

//Second Request 
jQuery('.reviewer-email input').blur(function(){ 
    //check the email rights using jquery.post 
}); 

jQuery('.reviewer-email input').ajaxStart(function(){ 
    //Show the warning 
}); 
jQuery('.reviewer-email input').ajaxStop(function(){ 
    //hide the warning 
}); 

当第一个关键事件发生时,“显示警告”部分运行!我也尝试了ajaxSend和ajaxComplete,但没有奏效!

任何想法如何我可以在我的输入框分别打电话给他们?

由于

+0

你可以发布您的代码? – Jags

.ajaxStart() documentation描述的,当被触发ajaxStart事件已注册与.ajaxStart()方法所有处理程序被执行。

你的情况的一种可能的解决办法是刚刚离开了ajaxStart/ajaxStop方法:

//First request 
jQuery('.company-name input').keyup(function(event){ 
    //Show the spinner 

    //get the alphabets and post them using jQuery.post. 
    //in jQuery.post success handler hide the spinner 
}); 

//Second Request 
jQuery('.reviewer-email input').blur(function(){ 
    //Show the warning 

    //check the email rights using jquery.post 
    //in jQuery.post success handler hide the warning 
}); 
+0

感谢您的回复! 我正在使用jQuery.post调用来处理大量dom元素的成功处理程序。我只想在请求/响应循环进行时才显示微调/警告。没有ajaxStart/ajaxStop方法可能吗?我能否为2种不同的文本输入附加2种不同的方法? 我会尝试成功回调方法,看看它是如何发展的。 –

+0

您好卡雷尔,您的解决方案工作!再次感谢! –