【发布时间】:2011-06-03 14:00:33
【问题描述】:
有没有办法通过 jQuery 加载 ascx 文件?
更新:
感谢@Emmett 和@Yads。我正在使用带有以下 jQuery ajax 代码的处理程序:
jQuery.ajax({
type: "POST", //GET
url: "Foo.ashx",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response)
{
jQuery('#controlload').append(response.d); // or response
},
error: function ()
{
jQuery('#controlload').append('error');
}
});
但我得到一个错误。我的代码错了吗?
另一个更新: 我正在使用
error: function (xhr, ajaxOptions, thrownError)
{
jQuery('#controlload').append(thrownError);
}
这就是我得到的:
无效的 JSON:
测试 =>(这个测试是我 ascx 中的标签)
还有我的 ascx 文件出错后!!!
另一个更新:
我的 ascx 文件是这样的:
<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label1" runat="server">Test</asp:Label>
但是在调用 ajax 时,我在 asp 中得到了这个错误::(
“DropDownList”类型的控件“ctl00_ddl”必须放置在带有 runat=server 的表单标记内。
感谢@Yads。但他的解决方案只适用于 html 标签。
【问题讨论】:
-
不可能吗?有没有办法将 ascx 文件转换为 aspx?还是更好的方法?
-
错误函数可以取一个请求对象,检查request.responseText找出错误是什么。
-
@Raika 您请求中的数据类型必须是 'html' 而不是 'json',顺便说一句,如果您想通知某人,则需要使用 @ 标签
-
@Yads。我是 jquery 的新手。你能用jquery更新你的答案吗? thnaks.... :P