Refresh div with Ajax call result

I would like to display the response of the ajax function below on a div in dom (update div). How can this be done without using heavy plugins.

url: 'http://dowmian.com/xs1/getcam.php',
type: 'GET',
data: {id: <?php echo $cam_id; ?>},
success: function(responseText){
},
error: function(responseText){
}
+3
source share
4 answers

It depends on the return value of your function getcam.php, but you are probably looking for a function html():

$.ajax({
    url: 'http://dowmian.com/xs1/getcam.php',
    type: 'GET',
    data: {id: <?php echo $cam_id; ?>},
    success: function(responseText){
        $('#update-div').html(responseText);
    },
    error: function(responseText){
    }
});

If you want to add #update-divdynamically, just like before an ajax call, you can do this with append():

$('.container').append($('<div/>').attr('id','update-div'));

References

+5
source

Inside success, do the following:

success: function(responseText) {
    $("#target").text(responseText);
},
+1
source

"success".

0

:

success: function(responseText) {
    $("#update-div").text(responseText.d);
},

0

All Articles