开发者

Cannot access data in the callback of a XMLHttpRequest in jQuery

When I run the following XmlHttpRequest

$.get('../entries/find_most_recent',
    {name:$("#name").val()}, 
    function(data) {
        console.log("data");
    });

The result can be seen in this Fireb开发者_JS百科ug screenshot:

Cannot access data in the callback of a XMLHttpRequest in jQuery

But when I remove the quotes from console.log("data"), like so:

$.get('../entries/find_most_recent',
    {name:$("#name").val()}, 
    function(data) {
        console.log(data);
    });

Nothing comes up in Firebug. The response is just a string, as can be seen in the screenshot above. How do I access it? Thanks for reading.


The object returned needs to be determined and dealt with appropriately.

From jquery.com "The success callback function is passed the returned data, which will be an XML root element, text string, JavaScript file, or JSON object, depending on the MIME type of the response. It is also passed the text status of the response."

http://api.jquery.com/jQuery.get/


I would have to say try setting your dataType to text in your $.get request and also double check "../entries/find_most_recent" for any errors (should their be an extension, like: ../entries/find_most_recent.cgi or .html or .php or etc.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜