我似乎无法让以下工作
restoJSON = { "name" : "Bloesem", "qName" : "bloesem", "address" : "Binnen Dommersstraat 13", "area" : "Jordaan", "tel" : "770 0407", "cuisine" : "European", "comment" : "Ver``rassingsmenu - slow service but 'gezellig' atmosphere", "booking" : "", "website" : "http://www.restaurantbloesem.nl/", "link" : "/?p=6", "rating" : 3, "price" : "3", "lat" : "52.382917", "lng" : "4.8854370000000245", "heading" : "0", "pitch" : "0", "zoom" : "0" };
jQuery.ajax({
type: "POST",
url: "updateDatabase.php",
data: restoJSON,
dataType: "text",
success: function(response, stat)
{
console.log("Response: " + response);
},
error: function()
{
console.log(arguments);
}
});
然后 updateDatatbase.php 在这些行上有变化以进行调试
echo "name: " . $_POST['qName'];
$json = json_decode($_POST['data'], true);
echo " " . $json['qName'];
foreach($_POST as $key=>$val) {
echo $key . "-x-" . $val;
}
我是一个相对的菜鸟,通过复制这个论坛的建议来完成工作,而不是完全理解。控制台日志如下 -请注意它是如何拆分链接行中的 = 的。
Response: name:
{"name":"Bloesem",
"qName":"bloesem",
"address":"Binnen_Dommersstraat_13",
"area":"Jordaan",
"tel":"770_0407",
"cuisine":"European",
"comment":"Verrassingsmenu_-_slow_service_but_'gezellig'_atmosphere",
"booking":"",
"website":"http://www_restaurantbloesem_nl/",
"link":"/?p-x-6\",
\"rating\" : 3,
\"price\" : \"3\",
\"lat\" : \"52.382917\",
\"lng\" : \"4.8854370000000245\",
\"heading\" : \"0\",
\"pitch\" : \"0\",
\"zoom\" : \"0\"
}