Mark Henry
Mark Henry

Reputation: 2699

Update div with the result of an Ajax-call

I would like to display the response of the ajax function below to a div in the dom (update div). How is this to 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){
}

Upvotes: 4

Views: 8158

Answers (4)

Brandt Solovij
Brandt Solovij

Reputation: 2134

Leverage the empty 'success' handler function you have.

Upvotes: 0

Frederik Wordenskjold
Frederik Wordenskjold

Reputation: 10221

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

$.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 append the #update-div dynamically, as in just before the ajax-call, you can do this with append():

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

References:

Upvotes: 5

coder
coder

Reputation: 13250

try this:

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

You can get more info from here

Upvotes: 0

robrich
robrich

Reputation: 13205

Inside success, do this:

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

Upvotes: 1

Related Questions