kmurph79
kmurph79

Reputation: 1202

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.

Upvotes: 0

Views: 336

Answers (1)

Milimetric
Milimetric

Reputation: 13549

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/

Upvotes: 1

Related Questions