So I am doing an ajax call, that is working, to grab some xml from my REST API.
When I echo the results I get, JQuery is saying that the return from ajax is null.
When I var_dump the results instead, the information is accepted by JQuery, but is obviously not formatted correctly, so it errors out.
Here is the jquery, which works fine.
$('.trackLine').click(function(e){
$.ajax({
url: "http://www.kazark.meacloudserver.com/index.php/search/Video/Zoolander",
dataType : "xml",
type:"GET",
//Successfull grabbed from API
success: function( xml ) {
xml = $.parseXML( xml );
//xml = xml[OperationRequest];
xml = xml.find( "title" );
console.log("is this shit here " +xml);
$( "<h1>" ).text( xml.title ).appendTo( "body" );
$( "<div class=\"content\">").html( xml.html ).appendTo( "body" );
},
// Code to run if the request fails; the raw request and
// status codes are passed to the function
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem!" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
},
// Code to run regardless of success or failure
complete: function( xhr, status ) {
alert( "The request is complete!" );
}
});
});
Here is my REST API php which works fine as well, except for the echo
$app->get('/search/:category/:term', function ($term, $category) {
$attributes = amazonCall($term, $category, null, null, true);
//var_dump($attributes);
echo "$attributes";
//echo"SOME STUFF";
/*
*/
});
both the var_dump and echoing some stuff return correctly to the js, but when I try the echo "$attributes", my JQuery says "TypeError: xml is null"
Also accessing the url in my browser works fine as well, echoing $attributes as I expected.
Please help! Thank you
So it seems changing the data- type in jquery to dataType : "text"
did the trick now in the console it says: is this stuff here [object XMLDocument]
which means its working (I think) now I just have to figure out how to manipulate this object
Thanks everyone! your speed responses are very appriciated.