user2173955
user2173955

Reputation:

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.

Upvotes: 4

Views: 21510

Answers (8)

Ihor Patychenko
Ihor Patychenko

Reputation: 196

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.

Upvotes: 0

George
George

Reputation: 36794

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.

Upvotes: 3

Setr&#225;kus Ra
Setr&#225;kus Ra

Reputation: 255

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

Upvotes: 0

Jeremy Gross
Jeremy Gross

Reputation: 89

here is the right success function :

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

Upvotes: 1

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);
}

Upvotes: 2

user1969752
user1969752

Reputation:

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

success: function (response) {

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

Upvotes: 3

K D
K D

Reputation: 5989

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

Upvotes: 0

Edwin Alex
Edwin Alex

Reputation: 5108

Try this,

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

Upvotes: 0

Related Questions