peter
peter

Reputation: 1038

ajax post error: NETWORK_ERR: XMLHttpRequest Exception 101 on android device

I have the following ajax post:

$.ajax({
    type: "POST",
    url: "http://sampleurl",
    data: {
        'email':$('#email').val(),
        'password':$('#password').val(),
    },
    cache: false,
    async: false,
    crossDomain: "true",
    beforeSend: function() { },
    complete: function() { },
    success: function(resp) {
        alert(resp);
        var result = $.parseJSON(resp);

        if (result.result == "Success") {   
            alert(emailID,password);
        }
        else {
            alert(result.msg);
        }
    },
    error: function(request, status, error) {
        //$("#LoadingImage").hide();
        alert("Result = " + error);
    }
});
return false;
});

It is returning with this error: NETWORK_ERR: XMLHttpRequest Exception 101 on android tablet.

I have read a bunch of SO posts on this error, most suggest that I set async to true. This DOES remove the error message- but it is still an error, and I never get valid data. It just seems to remove the error message which is not helpful.

Please help me.

Upvotes: 1

Views: 1549

Answers (2)

peter
peter

Reputation: 1038

Finally i got solution.. Android 4.1 and 4.2 introduce this new method: getAllowUniversalAccessFromFileURLs

Since it's not working on API below 16 the solution needs some few more lines, to assure that this inexistent method do not cause errors in previous API.

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN){
    fixNewAndroid(webView);
}

@TargetApi(16)
protected void fixNewAndroid(WebView webView) {
try {
    webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
} catch(NullPointerException e) {
}

Upvotes: 4

Jacek Gałązka
Jacek Gałązka

Reputation: 1

try use location in your domain , like ./directory/yourfile.php I have this problem in IE7

Upvotes: 0

Related Questions