javascript之使用 Jquery Ajax 方法时不允许方法错误

java哥 阅读:73 2026-07-28 15:07:40 评论:0

我正在使用 jQuery Ajax 方法与 Asp.net MVC 3.0

我的 jQuery 代码是

$.ajax({ 
       type: "POST", 
       url: "/HomePage/GetAllCategories", 
       contentType: "application/json; charset=utf-8",                 
       dataType: 'json', 
       success: function (result) { 
          alert(result); 
    } 
}); 

我的行动方法是

public JsonResult GetAllCategories() 
{ 
     return Json(null, JsonRequestBehavior.AllowGet); 
} 

我收到错误

POST http://localhost:50500/HomePage/GetAllCategories 405 (Method Not Allowed)

我的调试器没有命中此方法。

请您参考如下方法:

您已在 Controller 中创建了 GET 方法,并且已在 jquery AJAX 调用中将方法类型设置为 POST。

$.ajax({ 
       type: "GET", 
       url: "/HomePage/GetAllCategories", 
       contentType: "application/json; charset=utf-8",                 
       dataType: 'json', 
       success: function (result) { 
          alert(result); 
    } 
}); 


标签:ajax
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号