在ajax函数中返回ID

时间:2016-03-04 22:55:03

标签: javascript php ajax

我有一个ajax函数返回一个较小的距离计算在php中完成我需要它返回用户ID但它只返回-Infinity我在我的浏览器日志我错了可以帮助我

我的ajax

$.ajax({
    type : 'POST',
    data : formula,
    url : 'http://10.0.0.119/melleve/statusorig2.php',
    success : function(data){
        var retorno = JSON.parse(data);
        var mapdistance = $.map(retorno, function(index, value) {
            return index + value;
        });
        var ok = Math.max.apply(Math, mapdistance);
        alert(ok);

我的php

$latuser = '-22.8650697';
$longuser = '-43.287510499999996';
$sql = "SELECT * FROM cadast_moto WHERE carmodel = '2'"; 
$result = $conn->query($sql);
$encode = array();

while ($res = $result->fetch_array()) {
    $arr = array('idmoto' => $res['idmoto'], 'nomemoto' => $res['nomemoto'], 'latitude' => $res['latitude'], 'longitude' => $res['longitude']);
    //$encode[] = $arr;
    //echo (json_encode($arr));
    $theta = $longuser - $res['longitude'];
    $dist = sin(deg2rad($latuser)) * sin(deg2rad($res['latitude'])) +  cos(deg2rad($latuser)) * cos(deg2rad($res['latitude'])) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    $finaldist = $miles * 1.609344;
    $encode[$res['idmoto']] = $finaldist;
}
//echo $finaldist;
//echo (json_encode($finaldist));
echo (json_encode($encode));

0 个答案:

没有答案