jqueryajaxを使用していくつかの情報をphpページに渡そうとしています。送信しているstrinifiedJSONがnullであるとphpページがエコーバックし続ける理由を本当に理解できません
//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
何が悪いのでしょうか?ありがとう!