简体   繁体   中英

Jquery .ajax beforeSend seems to remove the click event handler from a button?

I'm trying to work with wordpress to stop an ajax request sent by Jquery and re-submit it with some additional data.

Here's how its working:

  • User clicks a submit button.

  • Wordpress submits the ajax request

  • I have a global beforeSend function set up using .ajaxSetup in this way:

    $.ajaxSetup( {beforeSend: monitorRequests } );

  • When wordpress submits the request, its intercepted by my function, which calls another function that submits another ajax request, while monitorRequests ' returns false, which cancels the original ajax request.

  • My own ajax request is sent, without any problems.

However here's the issue. After doing this once, if the user clicks the submit button again, wordpress's click handler is not called. I'm wondering why this is, whether this has anything to do with the ajax request being cancelled? Or anything else? What should I do to make it so that the click handler continues to be called?

想出来之后,Wordpress在ajax请求期间禁用了按钮,并且由于从未调用过wordpress的回调,它仍然被禁用。

$.ajaxSetup globally affects ajax calls in your page. You have no idea how many AJAX implemented in WP plugins and How each its custom implement.

Try narrow your scope to specific element. You may uses

$('.submit').bind('click', function(){ /* your fn */ }); 
//You can have many 'click' binding eg..
$('.submit').bind('click', function(){ /* another */ }); 
$('.submit').bind('click', function(){ /* yet another */ }); 

insert your script before existing one. You function will be called first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM