简体   繁体   中英

Async jQuery POST Request in Chrome

Using CoffeeScript, I have jQuery function that does some stuff, replaces the image source path, then tries to post asynchronously.

  $('.qualify_main_image').live 'click', (event) ->
     # some stuff
     $(this).find('img').attr('src', path)

     $.post(theHref)

I would like the image to change before making the POST request, and this works perfectly in Safari and Firefox. However, in Chrome, it waits for a response from the POST request to change the source path of the image.

Since CoffeeScript returns the last expression in the function, I thought adding 'true' to the end of the function might help, but it doesn't.

So, am I doing something wrong? What is going on here? Thank you.

I'm not sure how you're testing this, but it might have something to do with CoffeeScript because going with straight javascript doesn't have the problem you're describing. See the fiddle below:

$('.qualify_main_image').live('click', function(event){
     $(this).find('img').attr('src', 'http://www.travelblog.org/Wallpaper/pix/tb_mecsek_yellow_flower.jpg');

     $.post('/echo/json', function(data){ alert('post done.')});
});

http://jsfiddle.net/Dqg6A/7/

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