0
我已經在android中創建了本地主機服務器,我正在嘗試與我的ajax調用進行通信。我成功連接到了服務器,但無法接收response.xmlhttp狀態返回0 only.if我創建了服務器作爲國家環保總局本地主機服務器在android中
Ajax調用
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
document.getElementById("myDiv3").innerHTML=xmlhttp.readyState+"";
// document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
if (xmlhttp.readyState==4)
{
document.getElementById("myDiv1").innerHTML=xmlhttp.status+"";
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
// document.getElementById("myDiv2").innerHTML="2";
}
xmlhttp.open("GET","http://localhost:8888/Server",true);
//xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
}
服務器代碼
try{
String fromclient;
String toclient;
ServerSocket Server = new ServerSocket (8888);
System.out.println ("TCPServer Waiting for client on port 8888");
while(true)
{
Socket connected = Server.accept();
System.out.println(" THE CLIENT"+" "+
connected.getInetAddress() +":"+connected.getPort()+" IS CONNECTED ");
PrintWriter outToClient =
new PrintWriter(
connected.getOutputStream(),true);
outToClient.write("<html><head>hai</head></html>");
connected.close();
}
}
catch(Exception e)
{
}
}