How do I create a javascript object from an AJAX response?
This is what I'm currently doing:
PHP:
<?
echo '{status:"1", site:"example.com"}';
?>
JS:
success:function(data_response){
var object = eval( data_response );
console.log(object.url);
}});
I'm currently getting "undefined" on the console. How is this done?
Set the dataType of the ajax request to json, and the data_response will be an object already parsed to.
Or you could use $.getJSON also.
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