0

这就是ajax调用的样子

  $.ajax({
      url: 'http://localhost/placeadd.php',
      dataType: "json",
      type: "POST",
  data: {
      "location": {
      "lat": -33.8669710,
      "lng": 151.1958750
      },
      "accuracy": 50,
      "name": "Daves Test!",
      "types": ["shoe_store"],
      "language": "en-AU"
      },
      success: function( data){
    console.log(data.status+"<BR>");
      },
      error: function(request, status, error){
        console.log(status+"<BR>");
      }
      })
      })

我将如何访问 php 文件中的每个元素?例如访问“lat”是否只是 $_POST."location"."lat"?

4

1 回答 1

0
$.ajax({
    url: 'http://localhost/placeadd.php',
    dataType: "json",
    type: "POST",
    data: {
        "location": {"lat": -33.8669710,"lng": 151.1958750},
        "accuracy": 50,
        "name": "Daves Test!",
        "types": ["shoe_store"],
        "language": "en-AU"
    },
    success: function( data){
        console.log(data.status+"<BR>");
    },
    error: function(request, status, error){
        console.log(status+"<BR>");
    }
});

在 PHP 中:

<?php
    $post = json_decode($_POST);
    $lat = $post['location']['lat'];
    echo $lat;
?>
于 2012-12-08T08:44:50.143 回答