简体   繁体   English

Chrome中的jQuery异步POST请求

[英]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. 使用CoffeeScript,我可以使用jQuery函数完成一些工作,替换图像源路径,然后尝试异步发布。

  $('.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. 我希望在发出POST请求之前更改图像,这在Safari和Firefox中非常有效。 However, in Chrome, it waits for a response from the POST request to change the source path of the image. 但是,在Chrome中,它会等待POST请求的响应,以更改图片的源路径。

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. 由于CoffeeScript返回函数中的最后一个表达式,所以我认为在函数末尾添加“ true”可能会有所帮助,但没有帮助。

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. 我不确定您如何对此进行测试,但是它可能与CoffeeScript有关,因为使用直接的javascript并不会出现您所描述的问题。 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/ http://jsfiddle.net/Dqg6A/7/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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