Reputation: 6637
When testing my application on ubuntu and the chromium browser everything works OK, but when moving to the production machine which uses debian and the same chromium browser, I always get an ajax error 0.
Request:
$.ajax({
type: 'POST',
url: "http://localhost:8080/rest/setvalue/1234",
dataType: "json",
success: function(objResponse) {
showMessage("Done");
},
error: errorHandler
});
The errorHandler gets called on the production machine, although the server processes the request correctly!
Thanks for any ideas...
Frank
------ ADDED ------
Alert shown with the code
function errorHandler(xhr, ajaxOptions, thrownError) {
showAlert("Error", "Error: " + xhr.status + "\n" +
"Message: " + xhr.statusText + "\n" +
"Response: " + xhr.responseText + "\n" + thrownError); }
is:
Error: 0
Message: error
Response:
Upvotes: 1
Views: 300
Reputation: 7197
A parenthesis is missing in the success function.
showMessage("Done"; should be showMessage("Done");
Could you check if this solves the problem?
EDITED:
My opinion is that the problem is not code related. Most probably the AJAX request in your case is considered as a cross domain request and the same origin policy fails. That's why you get Error:0.
I managed to reproduce the case (in Windows OS) and I'm getting the same error in the following cases:
http://localhost:7001/MobileApp/index.html
and perform AJAX on http://www.example.com/MobileApp/test
.http://localhost:7001/MobileApp/index.html
and perform AJAX on http://127.0.0.1:7001/MobileApp/test
.http://127.0.0.1:7001/MobileApp/index.html
and perform AJAX on http://localhost:7001/MobileApp/test
http://192.168.1.2:7001/MobileApp/index.html
(where 192.168.1.2 is my private IP address) and perform AJAX on http://127.0.0.1:7001/MobileApp/test
.The above cases were considered as cross domain requests and I got the the error you are mentioning.
Obviously after configuring my hosts file and mapping IP addresses to host names etc some of the above issues were resolved because the requests were not considered as cross domain.
In conclusion I would suggest to investigate whether the same origin policy succeeds.
Upvotes: 1