开发者

Conflict when using ajaxStart & ajaxStop on 2 different text inputs

I'm stuck a little with ajaxStart / ajaxSend and their end methods. I have 2 different AJAX calls using jQuery.post running on 2 text inputs. The first one is for getting certain names list from my database, and I'm using ajaxStart / ajaxStop to show and hide a spinner. This works fine. The next AJAX call, is used to check an email status, again in my DB. I'm using ajaxStart / ajaxStop again to display a div with a message that the process is in progress, and then after the process is complete. Now, my problem is, when I type in the first text input, the ajaxStart for the 2nd input is called, and I can see the div! I tried using ajaxSend and ajaxComplete, but no luck!

Code:

//First req开发者_StackOverflow中文版uest
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
});

when the first key up event occurs, the 'Show the warning' part runs! I tried ajaxSend and ajaxComplete too, but didn't work!

Any ideas how I can call them separately on my input boxes?

Thanks


As described in .ajaxStart() documentation all handlers that have been registered with the .ajaxStart() method are executed when ajaxStart event is triggered.

One possible solution in your case would be to just leave out the ajaxStart/ajaxStop methods:

//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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜