我在jQuery的新手,我有一個問題: 我有兩個.aspx文件中:其中包含腳本從獲取數據的.aspx jQuery的AJAX
<script type ="text/javascript">
$(document).ready(function() {
var schemaName = GetURLParameters('schemaName');
var key = GetURLParameters('key');
$.post("dataloader.aspx", {
name: schemaName,
key: key
});
});
</script>
這將參數傳遞給其他頁面, 「dataloader.aspx」。這裏是 「dataloader.aspx.cs」 代碼:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
var schemaName = Request.Form["name"];
var key = Request.Form["key"];
Loader loader = ConnectionManager.getLoader();
Dictionary<string, string> name_value = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(schemaName))
{
var schema = loader.GetSchema(schemaName);
var qcontext = new SimpleLoader.BOService.QueryContext();
qcontext.InitQueryContext();
var element = loader.GetObjectByKey(schema, key);
var viselems = element._Schema.GetVisibleElems();
var cardElems = viselems.Where(x => !(x is SchemaElemDetail)).ToList();
foreach (var elem in cardElems)
{
var value = (element.GetValue(elem.Name) ?? "").ToString();
if (!string.IsNullOrEmpty(value))
{
name_value.Add(elem.Name, value);
}
}
Response.Write(name_value);
Response.Flush();
Response.End();
}
}
正如你看到的,I,M加入一些數據字典。我想通過jQuery將此字典發送到「clientcard.aspx」客戶端,但我不知道如何......您能幫助我嗎?我會非常感激。
您需要將字典序列化爲JSON。除了我之外沒有其他答案提到這一步。而且這是最關鍵的! – marteljn