最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to reload DIV content without refreshing whole page - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Mar 20, 2013 at 22:51 halfer 20.4k19 gold badges108 silver badges201 bronze badges asked Mar 19, 2013 at 9:43 user2173955user2173955
Add a comment  | 

8 Answers 8

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

success: function (response) {

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

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.

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.

发布评论

评论列表(0)

  1. 暂无评论