簡體   English   中英

json對象中的數據如何在ajax帖子中傳遞?

[英]How does data in a json object get passed in an ajax post?

這就是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”?

$.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;
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM