阿贾克斯提取数据返回jQuery中 [英] Extracting Ajax return data in jQuery

查看:129
本文介绍了阿贾克斯提取数据返回jQuery中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了jQuery和Ajax的,但我不能够得到响应转换成一个DIV元素。这是code:

I have done jQuery and Ajax, but I am not able to get the response into a Div element. This is the code:

的index.html

$.ajax({
    type:"POST",
    url: "ajax.php",
    data:"id="+id ,
    success: function(html){
        $("#response").html(data);
    }
});

据接收响应我的< D​​IV ID =响应>< / DIV>

以下code到 ajax.php 返回的index.html 文件:

The ajax.php returns following code to the index.html file:

<div id ="one"> OneVal </div>
<div id ="sub"> SubVal </div>

请问我能提取OneVal和Subval到一个变量,我怎么能提取OneVal和SubVal,而不是上面的反应呢?

Will I able to extract the OneVal and Subval into a variable, and how can I extract "OneVal" and "SubVal", instead of above response?

推荐答案

您可以使用 .filter 这是从响应创建一个jQuery对象:

You can use .filter on a jQuery object that was created from the response:

success: function(data){
    //Create jQuery object from the response HTML.
    var $response=$(data);

    //Query the jQuery object for the values
    var oneval = $response.filter('#one').text();
    var subval = $response.filter('#sub').text();
}

这篇关于阿贾克斯提取数据返回jQuery中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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