first time using json. I currently send a postcode to a php page, and try to store the result as json:
$("#make_ajax_call").click(function()
{
var form_postcode = $("#postcode").val();
$.ajax({
type: "POST",
url: 'mapping-ajax.php',
data: { postcode: form_postcode},
success: function(data)
{
var jsonObject = data;
var trimmedpostcode = jsonObject.trimmedpostcode;
alert(jsonObject);
alert(jsonObject.trimmedpostcode);
$('#result').html(data);
//alert('Load was performed.');
}
});
});
On the other end I use a php function echo json_encode($return_array);
The two alerts give me:
{"trimmedpostcode":"CO125WL","success":true,"outputstring":"CO125WL<br\/>"}
and
Undefined
How come the second one doesn’t return “CO125WL”? Do I need to tell javascript its a json object somehow?
Have you tried:
This is how I pull in my json information in Javascript with an ajax call.