Skip to main content
added 5 characters in body; edited title
Source Link
marc_s
  • 759.6k
  • 185
  • 1.4k
  • 1.5k

how How to get response with .load jqueryjQuery

I am working with .load function in jqueryjQuery to load a html page into a div with ajax but I have problem since server always doesn't send a html, sometimes it send a json and I want to get that josnjson with .load. 

I thought it would be a response in callback function in .load but it return undefined and just put that json into the div so how can I get that josnjson with .load.
the

The server send this json :

{ok : false}

Here is my jqueyjQuery code:

$( "#div").load( "url", function( response, status, xhr ) {
    ////how can I get the false result here response.ok return nothing!!!
    console.log(response.ok);
    if ( status == "error" ) {
        var msg = "Sorry but there was an error: ";
        $( "#div" ).html( msg + xhr.status + " " + xhr.statusText );
    }
});

how to get response with .load jquery

I am working with .load function in jquery to load a html page into a div with ajax but I have problem since server always doesn't send a html, sometimes it send a json and I want to get that josn with .load. I thought it would be a response in callback function in .load but it return undefined and just put that json into the div so how can I get that josn with .load.
the server send this json :

{ok : false}

Here is my jquey code:

$( "#div").load( "url", function( response, status, xhr ) {
    ////how can I get the false result here response.ok return nothing!!!
    console.log(response.ok);
    if ( status == "error" ) {
        var msg = "Sorry but there was an error: ";
        $( "#div" ).html( msg + xhr.status + " " + xhr.statusText );
    }
});

How to get response with .load jQuery

I am working with .load function in jQuery to load a html page into a div with ajax but I have problem since server always doesn't send a html, sometimes it send a json and I want to get that json with .load. 

I thought it would be a response in callback function in .load but it return undefined and just put that json into the div so how can I get that json with .load.

The server send this json :

{ok : false}

Here is my jQuery code:

$( "#div").load( "url", function( response, status, xhr ) {
    ////how can I get the false result here response.ok return nothing!!!
    console.log(response.ok);
    if ( status == "error" ) {
        var msg = "Sorry but there was an error: ";
        $( "#div" ).html( msg + xhr.status + " " + xhr.statusText );
    }
});
Source Link
Daniel.V
  • 2.5k
  • 7
  • 33
  • 61

how to get response with .load jquery

I am working with .load function in jquery to load a html page into a div with ajax but I have problem since server always doesn't send a html, sometimes it send a json and I want to get that josn with .load. I thought it would be a response in callback function in .load but it return undefined and just put that json into the div so how can I get that josn with .load.
the server send this json :

{ok : false}

Here is my jquey code:

$( "#div").load( "url", function( response, status, xhr ) {
    ////how can I get the false result here response.ok return nothing!!!
    console.log(response.ok);
    if ( status == "error" ) {
        var msg = "Sorry but there was an error: ";
        $( "#div" ).html( msg + xhr.status + " " + xhr.statusText );
    }
});