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

标签 jquery asp.net web-services

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

错误

Failed to load resource: the server responded with a status of 405 (Method Not Allowed) 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");
    }

网络服务 URL

http://localhost:12015/myWebService.asmx

<小时/>
 [WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
 public List<Categories>  GetCategories()
 {
      //code
 }

页面网址

http://localhost:11761/Default.aspx

编辑:当我刚刚包含 dataType: 'jsonp' 时,错误消失了,但现在又出现了另一个错误。

Uncaught SyntaxError: Unexpected token <
:12015/myWebService.asmx?op=GetCategories&callback=jQuery183010907560377381742_1356599550427&{}&_=1356599550438:3

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

相关

Link1 (解释)
Link2 (已解决)

最佳答案

试试这个

 [WebMethod]
 [ScriptMethod(UseHttpPost = true)]
 public List<Categories>  GetCategories()
 {
      //code
 }

或编辑web.config

<system.web>
    ...
    <webServices>
        <protocols>
              <add name="HttpSoap"/> 
              <add name="HttpPost"/> --> 
              <add name="HttpGet"/>
              <add name="Documentation"/>
              <add name="HttpPostLocalhost"/>
        </protocols>
    </webServices>
    ...
</system.web>

引用http://codeclimber.net.nz/archive/2006/12/22/How-to-enable-an-ASP.NET-WebService-to-listen-to-HTTP.aspx

关于jquery - 服务器响应状态为 405(不允许方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051432/

相关文章:

javascript - 帮助自动旋转无限 jquery 轮播。无法让轮播无限循环而不是 'rewind'

c# - 使用对象列表填充 UserControl Gridview

asp.net - 如何使用 HTTP Handler 传递 http 调用

java - 简单 RESTtful Web 服务实现中的错误

java - JBoss 中的自定义错误页面

javascript - 具有多级下拉菜单的最简单的 JQuery 动画导航栏

asp.net-mvc - 从下拉列表中选择的值不会从 jquery 对话框中发布

jquery - 将鼠标悬停在 Jquery SlideDown 菜单上时保持该菜单打开吗?

javascript - jquery 在回发时损坏

ios - 关于移动应用程序的 Web 服务配置?