Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery AJAX not working on IE 7/8

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.

like image 574
matthewb Avatar asked Nov 28 '09 21:11

matthewb


1 Answers

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.

Or you can do as @redsqaure suggests below and do this:

$.ajaxSetup({cache:false})

like image 62
Richard Avatar answered Oct 10 '22 14:10

Richard