我的页面上有一个链接,它创建一个 AJAX 调用页面本身并返回一个值。成功创建的服务器生成的响应变为空或有时AJAX的错误功能。我几乎尝试了所有方法,但无法提出解决方案。
这是我的 AJAX 函数:
var Ajax = {
AjaxCall: function (uri, jsonData, callBack, postParams) {
$.ajax({
cache: false,
type: "POST",
url: uri + ((uri.indexOf("?") > -1) ? "&" : "?") + "rand=" + new Date().format("ssmmHHddMMyyyy"),
data: JSON.stringify(jsonData),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
Ajax.AjaxCall_CallBack(msg, callBack, postParams);
},
error: function (msg) {
Ajax.AjaxCall_CallBack_Error(msg);
}
});
},
AjaxCall_CallBack: function (msg, callBack, postParams) {
callBack(msg, postParams);
},
AjaxCall_CallBack_Error: function (msg) {
alert(msg.responseText);
}
}
并且该函数进行 AJAX 调用
Ajax.AjaxCall('dummypage.aspx?ajax=6&edit=1&uID=' + uID, null, callback_func, [uID, 'Test Text', 0])
从服务器生成的值是这样的:
Table tbl;
TableRow tr;
TableCell tc;
Label lbl;
DropDownList ddl;
tbl = new Table();
tr = new TableRow();
tc = new TableCell();
lbl = new Label();
lbl.Text = "Choose one"
tc.Controls.Add(lbl);
tr.Cells.Add(tc);
tc = new TableCell();
ddl = new DropDownList();
ddl.Items.Add("Choose", "-1"));
ddl.Items.Add("First", "1");
ddl.Items.Add("Second", "2");
ddl.ID = "ddlContentType";
tc.Controls.Add(ddl);
tr.Cells.Add(tc);
tbl.Rows.Add(tr);
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
tbl.RenderControl(hw);
string renderedValue = sb.ToString();
hw.Close();
return HttpUtility.JavaScriptStringEncode(renderedValue, true);
我不明白为什么具有相同程序的同一页面上完全相同的结构有效,但不是这个?
提前致谢。