ben
ben

Reputation: 29777

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 Firebug screenshot:

alt text

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.

Upvotes: 3

Views: 362

Answers (2)

Lobabob
Lobabob

Reputation: 142

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.)

Upvotes: 0

brumScouse
brumScouse

Reputation: 3216

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/

Upvotes: 1

Related Questions