将Google地图点保存到数据库

时间:2013-07-15 14:20:15

标签: php javascript mysql ajax google-maps-api-3

我一直在玩谷歌地图试图进行巡视并保存数据库中的起点和方式点。

这是我用来传递值

的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响应视为“已更新”,但数据库没有任何反应 哪里出错了?

0 个答案:

没有答案