这是我正在尝试做的事情:
- 将传感器信息从 Android 平板电脑在线保存到 txt 文件
- 打开网页以使用 ajax 调用连续读取该数据
注意:网站和安卓应用同时运行
安卓部分:
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://.../save.php");
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
Log.i("postData", response.getStatusLine().toString());
//Could do something better with response.
}
catch(Exception e)
{
Log.e("log_tag", "Error1: " + e.toString());
}
JS部分
setInterval("DisplayBall()", 500);
function DisplayBall()
{
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
document.getElementById("TotalTime").value = 0;
//alert(xmlHttp.responseText);
AssignResult(xmlHttp.responseText);
}
}
//xmlHttp.open("GET", "TINBCoordinates.txt", true);
//xmlHttp.send();
xmlHttp.open("GET", "read.php", true);
xmlHttp.send();
}
为什么这两个会干扰并使我的程序无响应?