the server responded with a status of 405 (Method Not Allowed)

前端 未结 5 1304
夕颜
夕颜 2020-12-30 14:51

I am new to Web Sevice, I am getting the following error when I tried to run my page (Local) in Chrome Console

ERROR

相关标签:
5条回答
  • 2020-12-30 15:09

    try this

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

    or edit 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>
    

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

    0 讨论(0)
  • 2020-12-30 15:09

    I added a simple line on my friend's suggestion above the jquery ajax call

     jQuery.support.cors = true;
    

    Now it is working fine :)

    ONLY IN IE BROWSER

    I would be happy to know if it can be solved using different way as it is not recommended.

    Anyhow I asked this question again after many efforts and I got different error which was solved in this post here

    0 讨论(0)
  • 2020-12-30 15:12

    make your content type as "application/json; charset=utf-8", as follows

    $(document).ready(function() {
    $.ajax({
    type: "POST",
    url: "RSSReader.asmx/GetRSSReader",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
      // Hide the fake progress indicator graphic.
      $('#RSSContent').removeClass('loading');
    
      // Insert the returned HTML into the <div>.
      $('#RSSContent').html(msg.d);
     }
    });
    });
    

    also refer link

    0 讨论(0)
  • 2020-12-30 15:16

    Add Allow Access All Origin In The Server Side

    0 讨论(0)
  • 2020-12-30 15:21

    in my case it was failing becasue of there was not POST method in servet, but I had GET method.

    so I jsut changed the type:"GET", so it is working now.

    0 讨论(0)
提交回复
热议问题