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

时间:2011-09-26 10:44:32

标签: jquery ajax

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

代码:

//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,但是没有用!

我可以在输入框上单独调用它们吗?

由于

1 个答案:

答案 0 :(得分:0)

.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
});