使用Ajax调用的结果更新div

Mar*_*nry 4 javascript ajax jquery

我想将下面的ajax函数的响应显示给dom中的div(更新div).如何在不使用重插件的情况下完成此操作.

url: 'http://dowmian.com/xs1/getcam.php',
type: 'GET',
data: {id: <?php echo $cam_id; ?>},
success: function(responseText){
},
error: function(responseText){
}
Run Code Online (Sandbox Code Playgroud)

Fre*_*old 5

它取决于getcam.php函数的返回值,但您可能正在寻找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){
    }
});
Run Code Online (Sandbox Code Playgroud)

如果你想#update-div动态追加,就像在ajax调用之前一样,你可以这样做append():

$('.container').append($('<div/>').attr('id','update-div'));
Run Code Online (Sandbox Code Playgroud)

参考文献: