Phonegap ajax call with username/password not working
Hi guys,
We're writing an android app with Phonegap and jquery mobile (1.0a4).
To give a little background we have a login page that sends the username/password to our server, the server responds success or failure. If success we store the username/password in localStorage and reuse those credentials for every successive request. I'm having difficulty with the ajax call when I add
- username: window.localStorage.getItem("usr"),
password: window.localStorage.getItem("pwd"),
the ajax call seems to fail (not be sent). My error function gets called
- error: function(request, status, error) {
console.log("Error status " + status);
console.log("Error request status text: " + request.statusText);
console.log("Error request status: " + request.status);
console.log("Error request response text: " + request.responseText);
console.log("Error response header: " + request.getAllResponseHeaders());
console.log("Error error: " + error);
and returns error for the status, and 0 for the request.status everything else is blank.
I'm on a phone making a request to a remote server so of course this is cross domain but the login does work and the request actually is sent if I remove the username and password parameters on the ajax call.
Here is my full ajax call
- $.ajax({
url: "http://myserver/url",
username: window.localStorage.getItem("usr"),
password: window.localStorage.getItem("pwd"),
dataType: "json",
headers: {"Accept": "text/html, application/json"},
success: function(response) {
//do stuff
},
error: function(request, status, error) {
console.log("Error status " + status);
console.log("Error request status text: " + request.statusText);
console.log("Error request status: " + request.status);
console.log("Error request response text: " + request.responseText);
console.log("Error response header: " + request.getAllResponseHeaders());
console.log("Error error: " + error);
}
});