Skip to content Skip to sidebar Skip to footer

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/g

Solution 1:

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: <?phpecho$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:

Solution 2:

Inside success, do this:

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

Solution 3:

try this:

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

You can get more info from here

Solution 4:

Leverage the empty 'success' handler function you have.

Post a Comment for "Update Div With The Result Of An Ajax-call"