Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

Posted by Vuyiswamb under HTML 5 on 1/30/2014 | Points: 10 | Views : 4634 | Status : [Member] [MVP] [Administrator] | Replies : 1
Good Evening all

i am trying to post data coming from a form to the server and return a string , when i test this service works nicely. Its a Rest web api. now iam consuming it in Javascript Ajax like this

 <script type="text/javascript">
function ProcessRegistration() {
jQuery.support.cors = true;

$.getJSON("http://www.mydomain.mymaindomain.com/api/Registration/Create", function (data) {
alert(data);

});
} </script>


When i run this and i get an Error


Failed to load resource: the server responded with a status of 405 (Method Not Allowed) http://www.mydomain.mymaindomain.com/api/Registration/Create



i have added the headers in IIS

"Access-Control-Allow-Origin" "*"


in my web config of the service i have added

<system.webServer>

<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>

<...........


i have done all suggested by my research but i still get that error, try to restart the server but still the same.

Thank you for posting at Dotnetfunda
[Administrator]



Responses

Posted by: Sravan661 on: 2/2/2014 [Member] Bronze | Points: 25

Up
0
Down
Hi Vuyiswamb,

In the script you are using there is no input parameters as POST method accepts parameters.
You can post the data using XML or JSON

$("#btnAddProduct").click(function () {
$.post(
"api/Products",
$("#addBook").serialize(),
function (value) {
},
"json"
);

});


Refer this url for more Info
http://www.codeproject.com/Tips/678138/MVC-using-Web-API-and-JQuery-to-GET-or-POST-Data


Please mark as answer if satisfied . . .

sravan

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response