Method not Allowed Error in Jquery Ajax Method used
Method not Allowed Error in Jquery Ajax Method used
我使用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(方法不允许)
我的调试器没有击中这个方法
您已经在控制器中创建了GET方法,并且在jquery AJAX调用中将方法类型设置为POST。
$.ajax({
type: "GET",
url: "/HomePage/GetAllCategories",
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (result) {
alert(result);
}
});
只需在URL末尾添加"/":
url: "/HomePage/GetAllCategories/",
好的,试试这个。我正在使用getJson调用来尝试获取相同的数据。
$.getJSON("/HomePage/GetAllCategories",
function(returnData) {
alert(returnData);
});
在ajax调用中设置type GET
$.ajax({
type: "GET",
url: '@Url.Action("GetAllCategories","HomePage")' ,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (result) {
alert(result);
}
});
和行动:
[HttpGet]
public JsonResult GetAllCategories()
{
return Json(null, JsonRequestBehavior.AllowGet);
}
如果想通过POST然后:
$.ajax({
type: "POST",
url: '@Url.Action("GetAllCategories","HomePage")' ,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (result) {
alert(result);
}
});
和行动:
[HttpPost]
public JsonResult GetAllCategories()
{
return Json(null, JsonRequestBehavior.AllowGet);
}
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- 如何通过ajax刷新JSF填充的javascript变量
- 如何在php文件中获取$.post-ajax传递的值
- Replacing $ .ajax?
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- Ajax发布表单序列化,发布引号'
- 通过Ajax将JavaScript函数传递给PHP文件
- ajax请求的顺序总是不同的
- 如何显示Ajax Get-Method中的数据
- jQuery deferred method and ajax beforeSend()
- Javascript and AJAX post method
- jQuery on method with ajax response
- Jquery ajax with google app engine post method
- 在 ajax get-method Javascript 中发送对象
- return request method = GET but i send request = POST (ajax)
- NetworkError: 405 Ajax调用中Method Not Allowed错误
- Method not Allowed Error in Jquery Ajax Method used
- jQuery .ajax() Method
- Javascript AJAX method
- AJAX POST METHOD