繁体   English   中英

PHP中的回显未在HTML页面中显示

[英]The echo in php is not being displayed back in HTML page

我的应用程序获取当前坐标,并检查它是否存在于mysql database.im中,试图在html页面上获取mysql数据(phonegap应用程序)。 它在移动设备中完美运行。 但是在纹波仿真器中,它不显示数据。 PHP将数据发送回html。 我可以通过进入开发人员模式(F12)->源->波纹文件间接查看数据。但是它不能将数据显示到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>*

您可以看到响应:已连接1个somaiya是我返回的数据。 但是它没有显示在HTML上

.below是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>

尝试在波纹模拟器设置中将“跨域代理”设置为“远程”

您可以尝试使用JSON来代替JSON,而不是XMLHttpRequest(),它具有一些内置功能。

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;
 }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM