为什么我的ajax调用返回null

时间:2015-02-25 18:51:47

标签: javascript php jquery ajax echo

所以我正在进行ajax调用,这是有效的,从我的REST API中获取一些xml。

当我回应我得到的结果时,JQuery说ajax的返回值为空。

当我改变结果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和echo一些东西都正确地返回到js,但是当我尝试echo“$ attributes”时,我的JQuery说“TypeError:xml is null”

同样访问浏览器中的网址也可以正常工作,按照我的预期回显$属性。

请帮忙!谢谢

1 个答案:

答案 0 :(得分:0)

所以它似乎改变了jquery中的数据类型     dataType:&#34; text&#34;

做了这个伎俩 现在在控制台中它说: 这是这里的东西[object XMLDocument]

这意味着它的工作(我认为) 现在我只需要弄清楚如何操纵这个对象

谢谢大家! 你的速度反应很贴切。