php中的echo不会显示在HTML页面中

时间:2014-06-13 07:42:30

标签: php html mysql cordova ripple

我的应用程序获取当前坐标并检查它是否存在于mysql database.i中,试图在html页面上获取mysql数据(phonegap应用程序)。它在移动设备上完美运行。但在纹波仿真器中它不显示数据。 PHP正在将数据发送回html。我可以通过进入开发者模式间接看到数据(F12) - >来源 - >涟漪文件.. BUt它不会将数据显示到html页面。有什么可能的错误 下面是我在源文件中找到的纹波文件接收代码

jXHR.cb0({"headers":{"date":"Tue, 17 Jun 2014 07:07:51 GMT","server":"Apache","x-powered-by":"PHP/5.2.17","content-length":"181","connection":"close","content-type":"text/html"},"response":" *connected<br>1 somaiya<br>*

你可以看到响应:connected 1 somaiya是我得到的数据。但它没有在html上显示

。下面是html的代码

<!DOCTYPE html>
<html>
  <head>
    <title>Device Properties Example</title>


<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

// Wait for device API libraries to load
//

document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//
function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
var lat;
var lon;
// onSuccess Geolocation
//
function onSuccess(position) {

    var element = document.getElementById('geolocation');

    element.innerHTML = 'Latitude: '           + position.coords.latitude + '<br />' +
                        'Longitude: '          + position.coords.longitude  + '<br />' +
                        'Altitude: '           + position.coords.altitude              + '<br />' +
                        'Accuracy: '           + position.coords.accuracy              + '<br />' +
                        'Altitude Accuracy: '  + position.coords.altitudeAccuracy      + '<br />' +
                        'Heading: '            + position.coords.heading               + '<br />' +
                        'Speed: '              + position.coords.speed                 + '<br />' +
                        'Timestamp: '          + position.timestamp                    + '<br />';
lat= position.coords.latitude;
lon= position.coords.longitude;
var xmlhttp;

xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("t01").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://geolocation.webatu.com/Radius.php?lat="+lat+"&lon="+lon,true)
xmlhttp.send();
}

function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}
</script>

</head>
<body>
<p id="geolocation">Finding geolocation...</p>
<div id="main">
<div id="t01"></div>
  </div>
  </body>
</html>

2 个答案:

答案 0 :(得分:0)

尝试在纹波仿真器设置中将跨域代理设置为远程

答案 1 :(得分:0)

而不是XMLHttpRequest(),你可以尝试使用JSON jQuery可能更容易。它有一些内置函数。

Var Passvalues = 'lat="+lat+"&lon="+lon',
 jQuery.ajax({


url : geolocation.webatu.com/Radius.php',    
data: Passvalues,
dataType: 'JSON',
type: 'POST',
success: response_function
});

response_function(response){
 if(response.status == 1){
 //success response
 alert(response.message);

  document.getElementById("t01").innerHTML
  =response.message;
 }else{
  //failure response 
  alert(response.message);
  return false;
 }
 }