i write the following code to access page "JQueryPage.aspx" and get data from it using jQuery
我编写以下代码来访问页面“JQueryPage.aspx”并使用jQuery从中获取数据
<script type="text/javascript">
$.get
(
"JQueryPage.aspx",
function(data) {
alert("Data Loaded: " + data);
}
);
</script>
"JQueryPage.aspx" is just a page that contain DIV called 'resultsDIV' that contain the data that i want to return
the above code return data variable that contain "JQueryPage.aspx" html and i want to get DIV content from it ..
i have 2 questions:
1- how can i extract DIV content from data object
2- is this way is th best to get that data ?
“JQueryPage.aspx”只是一个包含名为'resultsDIV'的DIV的页面,其中包含我想要返回包含“JQueryPage.aspx”html的上述代码返回数据变量的数据,我想从中获取DIV内容。我有两个问题:1-如何从数据对象2-中提取DIV内容这种方式是获取该数据的最佳方式?
3 个解决方案
#1
2
Try using something like this:
尝试使用这样的东西:
<script type="text/javascript">
$.get
(
"JQueryPage.aspx", function(html) {
var page = $(html);
var div = $('#div1', page);
}
);
</script>
you can also look into the $.load
function
你也可以查看$ .load函数
#2
0
Jsut wrap the data in a call to jquery and you can use it like you would normally:
Jsut在调用jquery时包装数据,你可以像平常一样使用它:
$.get
(
"JQueryPage.aspx",
function(data) {
var dataDom = $(data);
$(someSelector, dataDom).each(function(){
alert($(this).html());
});
}
);
#3
0
- If the html markup of
JQueryPage.aspx
is valid xml, you can use dom parser to get the required div. - It depends - if all you want is to add the retrieved html to the existing DOM using a call to
document.appendChild
, yes. But if you need to parse and read values from the retrieved data, no, this is not. Pass data as a JSON string or xml.
如果JQueryPage.aspx的html标记是有效的xml,则可以使用dom解析器来获取所需的div。
这取决于 - 如果你想要的是使用对document.appendChild的调用将检索到的html添加到现有DOM中,是的。但是,如果您需要从检索到的数据中解析和读取值,不,这不是。将数据作为JSON字符串或xml传递。
#1
2
Try using something like this:
尝试使用这样的东西:
<script type="text/javascript">
$.get
(
"JQueryPage.aspx", function(html) {
var page = $(html);
var div = $('#div1', page);
}
);
</script>
you can also look into the $.load
function
你也可以查看$ .load函数
#2
0
Jsut wrap the data in a call to jquery and you can use it like you would normally:
Jsut在调用jquery时包装数据,你可以像平常一样使用它:
$.get
(
"JQueryPage.aspx",
function(data) {
var dataDom = $(data);
$(someSelector, dataDom).each(function(){
alert($(this).html());
});
}
);
#3
0
- If the html markup of
JQueryPage.aspx
is valid xml, you can use dom parser to get the required div. - It depends - if all you want is to add the retrieved html to the existing DOM using a call to
document.appendChild
, yes. But if you need to parse and read values from the retrieved data, no, this is not. Pass data as a JSON string or xml.
如果JQueryPage.aspx的html标记是有效的xml,则可以使用dom解析器来获取所需的div。
这取决于 - 如果你想要的是使用对document.appendChild的调用将检索到的html添加到现有DOM中,是的。但是,如果您需要从检索到的数据中解析和读取值,不,这不是。将数据作为JSON字符串或xml传递。