有一个Ajax调用的结果更新DIV [英] Update div with the result of an Ajax-call

查看:117
本文介绍了有一个Ajax调用的结果更新DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示的AJAX功能下面的DOM(更新DIV)一个div的响应。这是怎么回事,而无需使用笨重的插件来完成。

  URL:http://dowmian.com/xs1/getcam.php,
键入:GET,
数据:{ID:< PHP的echo $ CAM_ID; ?>},
成功:函数(responseText的){
},
错误:函数(responseText的){
}
 

解决方案

这取决于你的 getcam.php 函数的返回值,但你可能寻找在 HTML()功能:

  $。阿贾克斯({
    网址:http://dowmian.com/xs1/getcam.php,
    键入:GET,
    数据:{ID:< PHP的echo $ CAM_ID; ?>},
    成功:函数(responseText的){
        $('#更新-DIV)HTML(responseText的);
    },
    错误:函数(responseText的){
    }
});
 

如果你想#更新-DIV 动态追加,因为在之前的AJAX调用,您可以用为此追加( )

  $('集装箱')追加($('< D​​IV />')。ATTR('身份证','更新-DIV'));
 

引用

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

解决方案

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:

这篇关于有一个Ajax调用的结果更新DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆