Skip to content Skip to sidebar Skip to footer

Jquery $.post() Getting Canceled

I'm getting a 'canceled' status whenever I do a jquery $.post(). It seems like an asynchronous problem? I access the local project with http://127.0.0.1:8933/myproject/default/inde

Solution 1:

Use this, to cancel the default navigatin behavior of the <a>:

$('#mybutton').click(function(e) {  // <-- Add `e` here
    e.preventDefault();  // <-- Add this linevar post_url = get_url();
    var data = ...;
    do_action(post_url, data); 
});

I believe the AJAX request is being aborted by the browser because when clicking the link, although the request does get sent off, the link tries to navigate to a new page so the browser must abort open AJAX requests.

Solution 2:

You can try this...

$('#mybutton').live("click", function(e) {  
    e.preventDefault();
    var post_url = get_url();
    var data = ...;
    do_action(post_url, data); 
});

Depending on the version of jQuery you are using, you can use jQuery.live() or jQuery.on() method

When the e.preventDefault() method is called if this method is called, the default action of the event will not be triggered.

Resources:

Post a Comment for "Jquery $.post() Getting Canceled"