I'm pulling in XML data and I need to return it to the front end as JSON.
I'm processing user input via AJAX like this:
$.ajax({ url: '/process.php',
data: {category: 'sportingGoods'},
type: 'post',
success: function(output) {
console.log(output);
}
});
This is sent to process.php
if(isset($_POST['category']) && !empty($_POST['category'])){
$category = $_POST['category'];
//echo $category;
switch($category){
case 'automotive':
$amazon->automotive;
break;
case 'sportingGoods':
echo $amazon->sportingGoods();
break;
}
}
Then, I access a method in a class. In this case, $amazon->sportingGoods()
Now, sportingGoods() does a bunch of stuff, then returns a result set like this:
$xml = simplexml_load_file($signedUrl);
$json = json_encode($xml);
$products = json_decode($json,TRUE);
return $products;
The XML and JSON data is there. I can print_r($products) and print_r($xml) and see the results in the console. However, when I try and return it, I don't get anything. So, am I not returning an object? How can I gain access to the result?
Arrayjson_encode()insportingGoods()? jQuery will likely decode one round, but you're probably left needing to decode the other --console.log($.parseJSON(output));.