I want to send lonin request with user name and password to Funambol Server which has public ULR (not in localhost). I already have ID and password, and also i can login with my ID in Server, but when i want to use JavaScript to send the login request it dose not response me anything, my question is: Is there any special way to send the request and receive the returned data from Server? I tried the code below, but i did not get any result (the status result which I get: http.readyState = 4 and http.status = 0). If someone knows about this, please give suggestion how to send request and retrieve the data from response?
var http = false;
var user = "myid";
var pass = "mypassword";
if (navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function handle() {
if (http.readyState == 4) {
var response = http.responseText;
//var response = eval('(' + http.responseText + ')');
//+"--"+ http.readyState +"--"+http.status;
document.getElementById('p').innerHTML = "response: " + response.data;
//countcontacts();
}
}
function login() {
http.onreadystatechange = handle;
http.open("POST", "/123.125.221.15/login?action=login&login="+user
+"&password="+pass, true);
http.send(null);
}
function countcontacts() {
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
the_object = eval('(' + http.responseText + ')');
document.getElementById('p').innerHTML = "Found "
+ the_object.count + " contacts.";
}
}
http.open("POST", "/123.125.221.15/contact?action=count", true);
http.send(null);
}
And also why var response = eval('(' + http.responseText + ')');
throws this Exception:
uncaught syntaxerror unexpected token ) at file android_asset www index html
Thanks in advance!!