1

我一直在玩谷歌地图,试图进行游览并将起点和路径点保存在数据库中。

这是我用来传递值的java脚本代码

 function saveRoute() {

    var name = "<?php Print($log_username);?>";
    var waypts = [];
    var end = points.length-1;
    var dest = points[end].LatLng;
    if (document.getElementById("roundTrip").checked) {
      end = points.length;
      dest = points[0].LatLng;
    }
    data.start = {'lat': points[0].LatLng.lat(), 'lng': points[0].LatLng.lng()}
    data.end = {'lat': dest.lat(), 'lng':dest.lng()}

    for (var i=1; i<end; i++) {
        waypts[i-1] = [points[i].LatLng.lat(),points[i].LatLng.lng()]
        data.waypoints = waypts;
    }

    var str = JSON.stringify(data)

    var jax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
    jax.open('POST','process.php');
    jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    jax.send('command=save&mapdata='+str)
    jax.onreadystatechange = function(){ if(jax.readyState==4) {
    if(jax.responseText.indexOf('bien')+1)alert('Updated');
    else alert(jax.responseText)
    }}
  }

这是我的 php processing.php

     <? 
        ob_start(); 
        header('Cache-Control: no-store, no-cache, must-revalidate');

        $data = $_REQUEST['mapdata'];

        echo $data;


        mysql_connect('localhost','root','');
        mysql_select_db('mapdir');

        if($_REQUEST['command']=='save')
        {

          $query = "update mapdir set value='$data'";
          if(mysql_query($query))die('bien');
          die(mysql_error());
        }

        if($_REQUEST['command']=='fetch')
        {
          $query = "select value from mapdir";
          if(!($res = mysql_query($query)))die(mysql_error());      
          $rs = mysql_fetch_array($res,1);
          die($rs['value']);        
        }
      ?>

我总是将 ajax 响应视为“已更新”,但我出错的数据库没有任何反应?

4

0 回答 0