简体   繁体   中英

how to reload DIV content without refreshing whole page

I want to only replace the DIV content with the content i get. After i make a get request to the server using ajax.

    $.ajax({
    type: "GET",
    url: "http://127.0.0.1:8000/result/?age="+ ageData +"&occasion="+ 
    occasionData     +"&relationship="+ forData +"#",

    success: function () {

        $("#testDIV").load();
    }
});

"testDIV" is the id of the div with which i want to replace the content got from the server.

If you're looking to fill the <div> with what is returned from your script:

$.ajax({
    type: "GET",
    url: "http://127.0.0.1:8000/result/?age="+ ageData +"&occasion="+ 
    occasionData     +"&relationship="+ forData +"#",

    success: function (data) {

        $("#testDIV").html(data);
        //Puts response data inside <div id="testDIV"></div>
    }
});

Oh and please note the full stop within the http:// prefix. Unless your using a new protocol not known to many of us - you'll want that gone.

   $.ajax({
type: "GET",
url: "ht.tp://127.0.0.1:8000/result/?age="+ ageData +"&occasion="+ 
occasionData     +"&relationship="+ forData +"#",

success: function (response) {

    $("#testDIV").html(response);
}
});

Use the first argument of success handler which carries the content, and replace your div content with it using the .html() function:

success: function (data) {
    $("#testDIV").html(data);
}

here is the right success function :

success: function(htmlFromServer) {
     $("#testDIV").html(htmlFromServer);
}

Try this,

success: function (data) {
    $("#testDIV").html(data);
}
 var url = "ht.tp://127.0.0.1:8000/result/?age="+ ageData +"&occasion="+ 
    occasionData+"&relationship="+ forData +"#";
    $('#testDIV').load(url);

The simplest way to get this done is by using the .load function

var url = "http://127.0.0.1:8000/result/?age="+ ageData +"&occasion=" + occasionData     +"&relationship="+ forData +"#";
$("#testDIV").load(url);

Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has encountered an error or is otherwise incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and indicate whether it is a temporary or permanent condition. Likewise, user agents should display any included entity to the user. These response codes are applicable to any request method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM