$.ajax({
type: 'POST',
url: 'place/add',
data: {
lat: lat,
lng: lng,
name: name,
address: address,
phone: phone,
review: review,
category: category
},
success: function(data) {
alert(data);
alert(data.id);
// ......
});
The first alert gives:{"id":"2","success":true}, but the second: undefined
You need to specify your anticipated returned data type as JSON:
$.ajax({
type: 'POST',
dataType: 'json', // specifies the return type
url: 'place/add',
data: {
lat: lat,
lng: lng,
name: name,
address: address,
phone: phone,
review: review,
category: category
},
success: function(data) {
alert(data);
alert(data.id);
// ......
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With