jQuery .find()在服务器响应 [英] jQuery .find() in server response

查看:274
本文介绍了jQuery .find()在服务器响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在服务器响应中获取特定div内的文本。我使用Firebug来查看响应是什么,并且可以在返回的代码中看到我的元素,但由于某种原因,我可以使用jQuery来捕获它。这是我使用的:

$ p $ var response = $('< div />').html(serverData) ;
$('#uploadedFiles')。html($(response).find(#created)。text());
alert($(response).find(#created)。text());

尝试只返回任何内容,而不是文本或任何东西。注意:服务器响应不是来自jQuery ajax函数,而是来自jQuery SWFUpload插件,请问这个问题呢?

解决方案

何时运行代码?如果你在uploadedFile元素创建之前运行它,代码将不会找到它。



我测试了这个,它工作得很好,它提示asdf,然后在div元素中用asdf替换test:

 < script type =text / javascript> 

$(function(){
var response = $('< div />').html('<div id =created> asdf< / div> ('#created')。
alert(response.find ());
});

< / script>

< div id =uploadedFiles>测试< / div>

请注意, response 是一个jQuery对象,所以 $(response)是多余的。


I am trying to get the text inside a specific div in a server response. I used Firebug to see what the response was, and I can see my element in the returned code, but for some reason I can get jQuery to capture it. Here is what I am using:

var response = $('<div />').html(serverData);
$('#uploadedFiles').html($(response).find("#created").text());
alert($(response).find("#created").text());

Trying that just returns nothing, not text or anything. Am I doing this correctly?

Note: The server response is not from a jQuery ajax function, rather from the jQuery SWFUpload plugin, would this matter though?

解决方案

When are you running the code? If you run it before the uploadedFile element is created, the code will not find it.

I tested this, and it works just fine, it alerts "asdf" and then replaces "test" with "asdf" in the div element:

<script type="text/javascript">

$(function(){
    var response = $('<div />').html('<div id="created">asdf</div>');
    alert(response.find("#created").text());
    $('#uploadedFiles').html(response.find("#created").text());
});

</script>

<div id="uploadedFiles">test</div>

Note that response is alread a jQuery object, so $(response) is redundant.

这篇关于jQuery .find()在服务器响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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