我正在尝试使用 jquery ajax 将一些信息传递给 php 页面。我真的不明白为什么 php 页面不断回显我发送的字符串化 JSON 为空
//php
if ($type == "new" || $type == "update"){
$new_address = json_decode($_REQUEST['address'], true);
echo json_encode($new_address); //Null
}
//js
var string_encoded_address = JSON.stringify(address_obj.address);
string_encoded_address = encodeURIComponent(string_encoded_address);
console.log(string_encoded_address);
$.ajax({
type: "post",
url: "order_queries_templates/queries/address.php",
data: "type=new&user_id=" + user_id + "&address=" + string_encoded_address,
dataType: "json",
success: function (returnedData) {
console.log(returnedData);
}
});
这为我的data
财产提供了一个字符串:
type=new&user_id=8244&address=%7B%22companyName%22%3A%22test%20company%22%2C%22address1%22%3A%222420%20sample%20Road%22%2C%22city%22%3A%22SIOUX%20CITY%22%2C%22state%22%3A%22IA%22%2C%22zip%22%3A%2251106%22%2C%22cityStateZip%22%3A%22SIOUX%20CITY%2C%20IA%2051106%22%7D
它有什么问题?谢谢!