是否可以从web到应用程序获取javascript数据
我需要从网站(例如facebook)到我的.NET应用程序中获取innerHTML字符串列表。是否可以从web到应用程序获取javascript数据,javascript,c#,asp.net,.net,Javascript,C#,Asp.net,.net,我需要从网站(例如facebook)到我的.NET应用程序中获取innerHTML字符串列表。 是否有方法将以下函数的结果输入到我的应用程序中(我会将此数据放入列表): var data=new Array(); 对于(i=0;i,以下是一个示例: 请参见隐藏字段数组存储 客户端: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></titl
是否有方法将以下函数的结果输入到我的应用程序中(我会将此数据放入列表):
var data=new Array();
对于(i=0;i,以下是一个示例:
请参见隐藏字段数组存储
客户端:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var array_store;
window.onload = function () {
array_store = document.getElementById("array_store");
document.getElementById("array_disp").innerHTML = array_store.value;
};
function UpdateArray() {
var arr;
if (array_store.value == "") {
arr = new Array();
} else {
arr = array_store.value.split(",");
}
arr.push((arr.length + 1).toString());
array_store.value = arr.join(",");
};
</script>
</head>
<body>
<form id="form1" runat="server">
<span id="array_disp"></span>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="UpdateArray()" />
<input type="hidden" id="array_store" name = "ArrayStore" value = '<%=this.ArrayStore %>' />
</form>
</body>
</html>
查看有关将表单数据发布到.net MVC控制器的文档。这将为您提供大部分方法。然后查看如何在更新这些html字符串时将其发送到表单操作。
var JS_DATA = data; //get the js array as a variable
static List<string> data = new List<string>(); //make a new list
foreach (string str in JS_DATA)
data.Add(String.Format("{0}", str)); //add the whole js array to the list
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var array_store;
window.onload = function () {
array_store = document.getElementById("array_store");
document.getElementById("array_disp").innerHTML = array_store.value;
};
function UpdateArray() {
var arr;
if (array_store.value == "") {
arr = new Array();
} else {
arr = array_store.value.split(",");
}
arr.push((arr.length + 1).toString());
array_store.value = arr.join(",");
};
</script>
</head>
<body>
<form id="form1" runat="server">
<span id="array_disp"></span>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="UpdateArray()" />
<input type="hidden" id="array_store" name = "ArrayStore" value = '<%=this.ArrayStore %>' />
</form>
</body>
</html>
protected string ArrayStore = "";
protected void Page_Load(object sender, EventArgs e)
{
this.ArrayStore = Request.Form["ArrayStore"];
}