I'm trying to pass a some information to a php page with jquery ajax. I really can't understand why the php page keeps echoing back that the strinified JSON i'm sending is null
//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);
}
});
this gives me a string for my data
property:
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
What could be wrong with it? Thanks!