我有一个页面,其中包含几个使用Ajax的用户控件。当我尝试从此页面执行response.redirect时,Ajax会捕获该调用并且不允许重定向。
如何从Ajax页面执行response.redirect?
...谢谢
答案 0 :(得分:0)
您在用户控件中对AJAX操作有多少控制权?如果您可以修改客户端,最简单的方法是返回一个可以解析的JSON对象,并将要重定向的URL作为数据发送。在客户端获取数据后,只需将window.location.href设置为url即可。
使用jQuery,它看起来像:
$.ajax({
url: '/some/url',
dataType: 'json',
type: 'post',
data: $('form').serialize(),
success: function(data) {
if (data.Redirect) {
window.location.href = data.Redirect;
}
else {
...handle other responses...
}
}
... more options...
});
答案 1 :(得分:0)
将此添加到您的web.config
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>