开发者

jQuery $.ajax not submitting data

开发者 https://www.devze.com 2023-04-04 23:20 出处:网络
I\'m having a very weird jQuery AJAX problem that I can\'t figure out. The problem is that in IE9, only sometimes (I can\'t reproduce it), it doesn\'t submit any data, although the AJAX returns succe

I'm having a very weird jQuery AJAX problem that I can't figure out.

The problem is that in IE9, only sometimes (I can't reproduce it), it doesn't submit any data, although the AJAX returns successfully. As well, 1 AJAX POST will not send any data while the next one and any following on the same page will be successful.

The AJAX runs in the game on Big Shrimp Contest here: www.bigshrimpcontest.com/play

There are a few AJAX POSTs that happen during the game: (1) at the start (recording a start time), (2) when the game ends (recording the end time and stats/score from the game), (3) when the entry form is submitted (recording their name, email, etc). On the server, I'll see the request, but there is no POST or GET data. I've only seen the problem in IE9 (we've blocked IE6 & 7).

The game JavaScript is here: www.bigshrimpcontest.com/js/game.js The AJAX requests are line 258 (#1), line 40 (#2), line 99 (#3).

I've tried setting the cache to false, but that didn't make any difference. I w开发者_开发知识库as using jQuery Form, but I've removed it and the problem is persisting.

Any ideas? I'm willing to try things as long as they don't break the game.

I'm also concerned that I use the same methods on other projects that are much more important to save the data.

Edit

I've tried both of these options: adding a timestamp and changing the user-agent meta tag to IE8 and EmulateIE8, both with no luck.

Any other ideas?


In my opinion it's a jQuery's fault. I guess you should wait for the new version that fixes the problem - and in the meanwile you can add "EmulateIE8" to your meta-tags.


Your statement:

it doesn't submit any data, although the AJAX returns successfully.

It sounded like caching problem to me. According to jQuery cache:

cacheBoolean Default: true, false for dataType 'script' and 'jsonp'

If set to false, it will force requested pages not to be cached by the browser. Setting cache to false also appends a query string parameter, "_=[TIMESTAMP]", to the URL.

However, I probe the URL through FF Firebug, I didn't the additional "_=[TIMESTAMP]" being appended to your URL.

Check the accepted answer in this SO Question ajax-problem-in-ie9 and try appending the Timestamp manually instead through setting cache to false in jQuery.


So, I think I've found a solution: use GET (vs POST). I changed all of my requests to to $.ajax('...', { type : 'GET' ... }); and since then there have been no problems. I also had to shorten the variables so that the GET request wouldn't be too long for IE. This may have also been part of the solution, but I don't know for sure.

0

精彩评论

暂无评论...
验证码 换一张
取 消