Server responded with status 405 (method not allowed)

I'm new to Web Sevice, I get the following error when trying to launch my page ( Local ) in the Chrome console

ERROR

Failed to load the resource: the server responded with a status of 405 (method not allowed) http://localhost:12015/myWebService.asmx?op=GetCategories


Here is the related code:

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"); } 

Web service url

http://localhost:12015/myWebService.asmx


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

Page URL

http://localhost:11761/Default.aspx

EDIT: The error dataType: 'jsonp' away when I just turned on dataType: 'jsonp' But now there is another error.

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

When I clicked the link (which was mentioned in the error), it displays the page. Then what is the problem? I do not know what the error means (as well as what part of the code to display). Please, help.

Connected

Link1 (explanation)
Link2 ( SOLVED )

+4
source share
4 answers

I added a simple line to my friend's suggestion over jquery ajax call

  jQuery.support.cors = true; 

Now it works fine :)

ONLY IN IE BROWSER

I would be happy to know if it can be resolved in another way, as it is recommended .

In any case, I asked this question again after many efforts, and I had another error that was resolved in this post here

+2
source

enter your content type as "application / json; charset = utf-8" as shown below

 $(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 link to the link

+3
source

try it

  [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> 

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

+2
source

in my case this was unsuccessful because the servlet did not have a POST method, but I had a GET method.

so I changed the type: "GET", so it works now.

+1
source

All Articles