Neha Goel
Neha Goel

Reputation: 29

Ajax onreadystatechange not working with ajax synchronous request in firefox below 4 version

i am using ajax and jquery to send a synchronous http request.

I have to use synchronous request because i want to return some value from ajax function after evaluating result of the server side script.

i know synchronous request will freeze the browser but due to my requirement i will have to do this request.

i also knows that in synchronous request there is no use of onreadystatechange function we should evaluate our result after sending the request or below the send function.By doing this my code is in working state.

But, my problem is that when i used onreadystatechange function it is working in firefox >=4 version but not working in below firefox 4 version.

Please. help me in finding out whether problem is with the code or the browser.

i am not able to find out the bug now i am helpless...plz help here is my code

function test(txt_obj) {  
    var keywords = txt_obj.value;
    var SHttpRequestObject = false;  
    var url = "/speller/server-scripts/ifmisspelled_words.html" + '?keywords=' + keywords);  
    var speller_res = 0;  
    if (window.XMLHttpRequest){  
    SHttpRequestObject = new XMLHttpRequest();  
    } else if (window.ActiveXObject){  
    SHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");  
    }  
    SHttpRequestObject.open("POST", url, false);  
    if (SHttpRequestObject){  
    SHttpRequestObject.onreadystatechange = function() {  
    if (SHttpRequestObject.readyState == 4 && SHttpRequestObject.status == 200)  
    {  
    var result = eval("(" + SHttpRequestObject.responseText + ")");  
    if(result.error) {  
    speller_res = 1;  
    } else if(result.word_exist) {  
    speller_res = 1;  
    }  
    else if(result.word_not_exist)  {  
    speller_res = 0;  
    }  
    }  
    };  
    }  
    SHttpRequestObject.send(null);  
    return speller_res;  

    }  

Upvotes: 0

Views: 1506

Answers (1)

16dots
16dots

Reputation: 3070

From MDN:

onreadystatechange

Warning: This must not be used from native code. You should also not use this with synchronous requests.

Upvotes: 2

Related Questions