服务器响应状态为405(方法不允许)

Mr_*_*een 6 asp.net jquery web-services

我是Web服务的新用户,当我尝试在Chrome控制台中运行我的页面(本地)时出现以下错误

错误

无法加载资源:服务器响应状态为405(方法不允许) http://localhost:12015/myWebService.asmx?op=GetCategories


这是相关的代码:

jQuery的

 $.ajax({
     url: "http://localhost:12015/myWebService.asmx?op=GetCategories",
     type: "POST",
     ------------
     ------------
    success: function (data) {                    
         var categories = data.d;
         $.each(categories, function (index, category) {
             category.CategoryId).text(category.CategoryName);
         });
    },
    error: function (e) {  //always executing 'error' only
         alert("hello");
    }
Run Code Online (Sandbox Code Playgroud)

网络服务网址

http://localhost:12015/myWebService.asmx


 [WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
 public List<Categories>  GetCategories()
 {
      //code
 }
Run Code Online (Sandbox Code Playgroud)

页面URL

http://localhost:11761/Default.aspx

编辑:当我刚刚包括dataType: 'jsonp'但错误消失但现在又出现了另一个错误.

未捕获的SyntaxError:意外的令牌<
:12015/myWebService.asmx?op=GetCategories&callback=jQuery183010907560377381742_1356599550427&{}&_=1356599550438:3

当我点击链接(错误中提到的)时,它正在显示页面.那可能是什么问题?我不知道错误意味着什么(以及代码的哪一部分显示).请帮忙.

有关

Link1(解释)
Link2(已解决)

Mr_*_*een 2

我根据朋友的建议在 jquery ajax 调用上方添加了一行简单的代码

 jQuery.support.cors = true;
Run Code Online (Sandbox Code Playgroud)

现在它工作正常:)

仅限IE浏览器

我很高兴知道是否可以使用不同的方式解决它,因为不建议这样做。

不管怎样,经过多次努力,我再次问了这个问题,我得到了不同的错误,该错误在这篇文章中得到了解决