Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE not triggering jQuery Ajax success

I'm working on a script to load some images async using jQuery.

Here is a code snippet of the function that loads the images -

try{
    for(img in imgsArray){
        $.ajax({    
            async: false,
            type: "get",
            url:imgsArray[img],
            success:function(imgFile){
                alert("success");
                //do something useful
            },
            error:function(XMLHttpRequest,status,error){
                //do nothing
            }
        });//ajax
    } 
}
catch(e){
    //oops
}

I have tested this in Firefox, Webkit (Safari,Chrome) and it works.

The images are in a folder on the server and I'm using jQuery 1.3.

any ideas?

like image 348
Peter Avatar asked Apr 23 '09 16:04

Peter


People also ask

Why is ajax success not working?

ajax post method. The reason was my response was not in the JSON format so there was no need for the dataType: 'json' line in the submit method. In my case, the returned response was in text format that's why it was not going to success event. Solution: Remove dataType: 'json' line.

What triggers ajax success?

Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess event. Any and all handlers that have been registered with the . ajaxSuccess() method are executed at this time. $( ".

Is ajax successful deprecated?

ajax function is deprecated.


2 Answers

A simple fix of this problem is to provide the jQuery setting dataType : 'text' or dataType : 'xml' or dataType : 'json' or any other available response type.

I had same problem, but it's working fine after specifying the dataType setting in the .ajax call.

IE is really not an intelligent browser, it doesn't assume the default value string.

Try it... good luck.

like image 169
Amber Mahajan Avatar answered Sep 18 '22 09:09

Amber Mahajan


Try setting the cached-option to false.

   $.ajax({        
            async: false,
            cache: false, 
            type: "get",
            url:imgsArray[img],
            success:function(imgFile){
                    alert("success");
                    //do something useful
                    },
                    error:function(XMLHttpRequest,status,error){
                    //do nothing
            }
    });//ajax
like image 43
John Korsnes Avatar answered Sep 22 '22 09:09

John Korsnes