JSON is not being recognised
Posted
by richzilla
on Stack Overflow
See other posts from Stack Overflow
or by richzilla
Published on 2010-04-15T12:13:27Z
Indexed on
2010/04/15
12:23 UTC
Read the original article
Hit count: 210
Hi All,
Im having a bit of trouble getting my JSON to be recognised by my web page. I have validated JSON that im getting returned from server, so i know that is correct, however my javascript function is not doing anything with it. My succes function is as follows:
success: function(data) {
$('input[name=customer_name]').val(data.name);
$('textarea[name=customer_address]').text(data.address);
$('input[name=customer_email]').val(data.email);
$('input[name=customer_tel]').val(data.tel);
$('input[name=user_id]').val(item.id);
}
Yet the fields are not being repopulated with the data that is returned, if it helps, a sample of my JSON data:
{
"name": "Terry O'Toole",
"address": "Terrys House\nTerry Street\nTerrysville\nTerrytown\nTT1 6TT",
"email": "[email protected]",
"tel": "05110000000"
}
Any help would be appreciated.
[EDIT]
Expanded ajax call:
$.ajax({
url: "<?php echo site_url('user/users/ajax'); ?>",
type: 'POST',
data: {"userid": item.id},
success: function(data) {
$('input[name=customer_name]').val(data.name);
$('textarea[name=customer_address]').text(data.address);
$('input[name=customer_email]').val(data.email);
$('input[name=customer_tel]').val(data.tel);
$('input[name=user_id]').val(item.id);
}
})
});
© Stack Overflow or respective owner