我想将带有用户名和密码的lonin请求发送到具有公共ULR(不在localhost中)的Funambol Server。我已经拥有ID和密码,而且我可以在服务器中使用我的ID登录,但是当我想使用JavaScript发送登录请求时,它不会回复我任何问题,我的问题是:是否有任何特殊的方式来发送请求并从服务器接收返回的数据?我尝试了下面的代码,但我没有得到任何结果(我得到的状态结果:http.readyState = 4和http.status = 0)。如果有人知道这一点,请提供建议如何发送请求并从响应中检索数据?
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);
}
还有var response = eval('(' + http.responseText + ')');
抛出此异常的原因:
uncaught syntaxerror unexpected token ) at file android_asset www index html
提前致谢!!