0

I have a website which I am trying to make a request via web API to the database. The API basically updates a bit field (in this case from 0 to 1).

Error:

This is all from the console.

OPTIONS  http://123.123.123.123:12345/project/webapi.svc/category/api/1/do/something 405 (Method Not Allowed)

send @ jquery-1.12.4.js:10254
ajax @ jquery-1.12.4.js:9738
click @ PageModal.js:10
(anonymous) @ jquery-ui.js:12443
dispatch @ jquery-1.12.4.js:5226
elemData.handle @ jquery-1.12.4.js:4878

XMLHttpRequest cannot load http://123.123.123.123:12345/project/webapi.svc/category/api/1/do/something. Response to page.aspx preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://123.123.123.123' is therefore not allowed access. The response had HTTP status code 405.

Request:

$.ajax({
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    url: "http://123.123.123.123:12345/project/webapi.svc/category/api/1/do/something",  //method Name 
    data: JSON.stringify({ id: ticketId }),
    dataType: 'json',
    error: function (msg)
        {
            alert("error: " + msg.status);
        }
 });

The only thing I can find on this are people who are trying to access the API from a different domain but I am on the same domain. I also have an iOS app which can POST without an issues however it seems the website is having issues.

Question:

How can I fix this 405 error? What is happening here?

Justin
  • 315
  • 2
  • 4
  • 18
  • look into CORS - that's the problem you're having. – Dan Field Feb 14 '17 at 19:53
  • possible duplicate http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource – Rick james Feb 14 '17 at 19:54
  • Possible duplicate of ["No 'Access-Control-Allow-Origin' header is present on the requested resource"](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Rick james Feb 14 '17 at 19:54
  • Aren't those links dealing with cross-domain requests. – Justin Feb 14 '17 at 19:57

1 Answers1

0

I think it's an api backend problem you probably need to add permission to post in your api controller

405 method not allowed web api

Community
  • 1
  • 1