我想抓住一個字符串,我正在閱讀從XML文件到JS函數。出於某種原因,Chrome中的調試器表示Glist中的值不是字符串。JS不識別隱藏字段中的字符串?
代碼:
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<%@ Page Language="C#" %>
<title>GAGEmobile</title>
<link rel="stylesheet" href="/Content/MenuStyle.css" />
<script type="text/javascript" src="Scripts/jQuery.js"></script>
<script type="text/javascript" src="Scripts/Scripts.js"></script>
</head>
<body id="generalBody" runat="server" dir="rtl">
<form runat="server" id="hidden">
<input type="hidden" runat="server" value='' id="Glist" />
</form>
<%
var reader = new GAGEmobile.Models.ReadXML();
var data = reader.getDataFromXML("https://gagemobile-
demo.servicebus.windows.net/gagemobile/gage/15/sample/david/blah");
this.Glist.Value = data;
%>
<script type="text/javascript">
$(document).ready(function() {
displayGageInfo(String("<%: Glist.Value %>"));
});
</script>
</body>
</html>
在爲Glist字符串爲:
"Gage number|C-01001|Gage type|Caliper|Gage size|1 |Units of measure|Inches|Gage description|Digi inside w absolute encoder|Storage location|Tool Crib|Current location|Tool Crib|Status|Available|Owner|Company|Group|Calib Group|EmailTo|Bobby Mohr|Last calib date|3/28/2013|Calib due date|9/28/2013|Last RR date|9/5/2012|RR due date|9/5/2013|Last maintenance date|2/27/2013|Maintenance due date|2/27/2015|Manufacturer|Fowler|Model number|FIC-23451|Serial number|18732|Comment|CALIBRATION GROUP EXPLANATION
We defined the Calibration Group as a set of gages that will be calibrated all at the same time. We set this value using the Group field above. This allows us to easily filter for these gages and gather them for calibration. SCHEDMAINTDUE EXPLANATION We have also used the user defined fields to create a new field called SchedMaintDue. This field allows us to define a Scheduled Maintenance Due Date for easy access to filtering and reference of maintenance cycles on our gages."
雖然我已經在服務器代碼一切字符串是好的。當我傳給JS的時候出了點問題,我不知道爲什麼。
我試過在JS中使用escape()和toString()函數。發生錯誤發生在'displayGageInfo(String(「<%:Glist.Value%>」));'作爲一個無法識別的標記
,讀取XML的ASP.NET:
public string getDataFromXML(string url)
{
var xml = new XmlDocument();
xml.Load(url);
return xml.InnerText;
}
字符串是否包含那些雙引號? (開始和結束) –
@millimoose當服務器端評估表達式時,「值」是正確的。 –
您尚未發佈發生問題的客戶端代碼。或者輸入字段在DOM檢查器中是否具有預期值。另外,使用內聯腳本也有點令人困惑。 – millimoose