views:

106

answers:

2

I am trying to debug the reason why my ajax get/post is not working in IE 7/8

Here my code:

$.ajax({type: "POST", dataType:'html',url: "/places/set_member/add/",data: "place_id="+place_id ,
                       beforeSend:  function() {$("<span class='notice'>Saving...</span>").prependTo('body');},
                       success: function(){
                        $.ajax({type:"GET",url:url,success:function(html){$('div.place-list .ui-tabs-panel').html(html);},complete:function(){resetAddThis();}})
                       },
            complete: function() {
                            $('span.notice').fadeOut(500);
          $('span.notice').remove();
                            }});

Now this works fine in FF Safari Win/Mac but not in IE 7/8

I downloaded fiddler and watched the calls, the script is supposed to send data the server and then re-load the HTML which now has new updated information. What is happening is the first call gets a error 500 but, then after the html is reloaded, and the same action is done again, it will send, with 200ms, so it give the appearance that it is not saving, which it does only on the second try.

Is there something I am doing wrong, or something I need to add? This is a php loop so this function is being applied to the same link on 20-30 items on the page.

+2  A: 

IE caches ajax calls. make sure that you include a random number or random string in your call, such as &rand=[some randomly generated something] and try it again.

Jason
A: 

IE caches all ajax calls which are not POST type. I have found that it is best to make all Ajax calls POST to avoid IE doing this, even if you post empty data.

Richard
I will try that, so the reason i see the first 500 internal error, is because the request was already sent before and cached?
matthewb
Thank you, by doing 1 post and have that return the html fixes my issue, I am no longer doing GET's for anything.
matthewb
just use the global $.ajaxSetup({cache:false}). This turns cache off for all xhr requests. Dont post when you want to get....
redsquare