所以我正在做一个ajax调用,它正在工作,从我的RESTneneneba API中获取一些xml。
当我回显我得到的结果时,JQuery表示ajax的返回为null。
当我改为var_dump结果时,JQuery接受了信息,但显然格式不正确,所以它会出错。
这是jquery,它运行良好。
$('.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!" );
}
});
});
这是我的REST API php,它也可以很好地工作,除了echo
$app->get('/search/:category/:term', function ($term, $category) {
$attributes = amazonCall($term, $category, null, null, true);
//var_dump($attributes);
echo "$attributes";
//echo"SOME STUFF";
/*
*/
});
var_dump和回显一些东西都会正确地返回到js,但当我尝试回显"$attributes"时,我的JQuery会说"TypeError:xml为null"
在我的浏览器中访问url也很好,正如我所期望的那样回显$attributes。
请帮忙!感谢
因此,似乎将jquery中的数据类型更改为dataType:"text"
成功了现在控制台上显示:这里有这些东西吗[object XMLDocument]
这意味着它有效(我认为)现在我只需要弄清楚如何操作这个对象
谢谢大家!你的速度反应非常及时。