C# 重定向回Default.aspx
我有一个default.aspx(c#)页面,该页面对返回JSON对象的C# 重定向回Default.aspx,c#,jquery,ajax,postback,webmethod,C#,Jquery,Ajax,Postback,Webmethod,我有一个default.aspx(c#)页面,该页面对返回JSON对象的WebMethod进行简单的Post AJAX调用,这样我就可以填充数据表。在我引入登录页面之前,一切都很好。现在,当用户在登录后被重定向到默认页面时,帖子永远不会出现在FireBug中 这是我的AJAX调用: $.ajax({ type: 'POST', url: '/Default.aspx/GetValueDateSummary', content
WebMethod
进行简单的Post AJAX调用,这样我就可以填充数据表。在我引入登录页面之前,一切都很好。现在,当用户在登录后被重定向到默认页面时,帖子永远不会出现在FireBug中
这是我的AJAX调用:
$.ajax({
type: 'POST',
url: '/Default.aspx/GetValueDateSummary',
contentType: 'json',
data: {},
sucess: function (response) {
renderTable(response.d);
},
error: function (errMsg) {
$('#errorMessage').text(errMsg);
}
});
});
其背后的代码是:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public static List<ValueDateSummary> GetValueDateSummary()
{
some code in here.....
return drList;
}
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json,UseHttpGet=true)]
公共静态列表GetValueDateSummary()
{
这里有一些代码。。。。。
返回DRL列表;
}
是否使用ScriptManager对象?如果是这样的话,我相信您需要启用页面方法才能使其工作
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
应该是
success: function (response) {
好的,我把它分类了
这里是completeajax调用,似乎我缺少了正确的contentType和dataType
$.ajax({
type: 'POST',
url: 'Default.aspx/GetValueDateSummary',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success: function (response) {
console.log(response);
alert(response.d);
renderTable(response.d);
},
error: function (errMsg) {
$('#errorMessage').text(errMsg);
}
});
可以显示一些代码吗?$.ajax({type:'POST',url:'/Default.aspx/GetValueDateSummary',contentType:'json',data:{},suces:function(response){renderTable(response.d);},error:function(errMsg){$('#errorMessage').text(errMsg);}}}});firebug是否显示任何JS错误?如果您在ajax调用出现之前立即
console.log
,它会出现吗?没有firebug错误Matt-在NET选项卡中只有帖子,没有my GET的迹象您会说“没有my GET的迹象”,但上面的代码是帖子。您检查过了吗?EnablePageMethods只会导致生成用于调用页面方法的JavaScript代理。如果您使用jQuery发出请求,则不需要该JavaScript,因此可能不希望浪费字节和客户端解析时间。是的,不使用ScriptManager这可以解释为什么从未调用renderable
,但是没有解释为什么从来没有提出请求。您还有两个ajax函数的关闭。});好的,谢谢你的检查。除了指出您发布的代码中的错误之外,我真的帮不上什么忙。你有一个小提琴或更多的代码,我们可以看到吗?嗨,马特,很好地发现了打字错误-虽然没有什么区别,因为你认为是维尼发现了打字错误。我将继续并假设Vinny也发现的额外结束只是复制和粘贴一行太多的结果,因为否则这将是一个语法错误,应该出现在Firebug中。
$.ajax({
type: 'POST',
url: 'Default.aspx/GetValueDateSummary',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success: function (response) {
console.log(response);
alert(response.d);
renderTable(response.d);
},
error: function (errMsg) {
$('#errorMessage').text(errMsg);
}
});