【发布时间】:2014-10-13 18:56:09
【问题描述】:
大家好,我想弄清楚如何从 ASPX 页面中的 DIV 获取值。目前,下面的代码正在返回完整的 html 正文(如果您右键单击 aspx 页面并查看源代码,它会看起来)。
但是,每次我检查返回的 html 时,它似乎都没有我在 Visual Studio 中为 DIV 提供的 ID 名称。
aspx代码:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="excelData.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="returnableData" runat="server"></div>
</form>
</body>
</html>
returnableData 是我要获取 innertext 的 div id。
JS代码为:
$.ajax({
type : 'GET',
async : false,
url : "excelData.aspx",
dataType: 'html',
data : {range: "A6"},
success : function (Data) {
var theReturnedData = $response.filter('#returnableData').text();
console.log(theReturnedData);
},
error : function(Data) {
console.log('error');
}
});
错误发生就行了:
var theReturnedData = $response.filter('#returnableData').text();
重新调整的 ajax 调用的源代码如下所示:
LOG: It's one of the most important games in the world!
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="excelData.aspx?range=A6" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZHTGmy0pCtoTD5qZ7o7ahrANn9wvWGc9h813Indizofg" />
</div>
<div>
</div>
</form>
</body>
</html>
从上面的代码可以看出,它确实在 div 中看到了它应该具有的值:
LOG: It's one of the most important games in the world!
但它不在 div 内...而且 div 本身没有甚至没有 ID ???
【问题讨论】:
标签: jquery asp.net ajax vb.net get