DavidBrown
DavidBrown

Reputation: 192

Content not returned during AJAX call

I attempting to load page content on a jQuery Mobile site via an AJAX call to the desktop version of the same site, which is generating the content for each page as a JSON object. I have confirmed that the JSON objects are good (i.e.: if you place the URLs into the browser, a good JSON object displays). The section of each JSON object that I am attempting to display is identified as "content" in the object itself.

On the jQuery Mobile page, I am placing a function to call the relevant JSON object and replace the content of that page with the JSON content. The function is as follows:

function processJSON(url, id){
        $.ajax({
            url: url,
            data: null,
            success: $(id).html(response.content),  
            dataType: 'json',
        });//ends ajax
    };//ends processJSON

The arguments for the function are as follows: "url" is a variable set equal to the URL of the appropriate JSON object, and "id" is the id of the div the content of which I want to replace with the JSON content. This page is living on the same server as the desktop version of the site, on an "m." subdomain.

When I place this on a test server, I receive an error in the console stating "Uncaught ReferenceError: response is not defined." Does this mean that the function is not receiving any JSON response, or that it cannot identify the "content" section of the JSON object? How do I correct this?

Thanks for your assistance.

Upvotes: 0

Views: 108

Answers (1)

Ilya
Ilya

Reputation: 29693

from jquery.ajax doucumentation

success Type: Function( PlainObject data, String textStatus, jqXHR jqXHR ) A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object.

success: function(response)
{  
   $(id).html(response.content)  
}

Upvotes: 1

Related Questions