1

I am calling a API Delete function it accept only DELETE verb.

I have tried

$.ajax({
url: 'http://myurl',
type: 'DELETE',
success: function(result) {
    // Do something with the result
});

But It shows Request Method as OPTIONS in Response Header.

Can anybody help me how i can send DELETE verb with ajax request.

Imran Rashid
  • 3,352
  • 4
  • 31
  • 41

3 Answers3

2

"...But It shows Request Method as OPTIONS in Response Header."

It sounds like a cross domain request issue. Are you making the request from the same domain, or a different domain? And furthermore, what's the response? I'm also guessing that there isn't a second request, because the second request would essentially be your original request if the browser determined you can send that request from the options response. The options request is the browser asking if it can make this other request. The options response essentially tells the browser from which domains certain requests can be made (or something along those lines).

Read more about Cross-Origin Resource Sharing here

JayC
  • 7,053
  • 2
  • 25
  • 41
  • I am sending request from different domain and in test client when i test with same url it works fine but with code it return bad request i think because of different response header. If i send it from same domain it will work? – Imran Rashid May 19 '12 at 02:00
  • A `DELETE` request to a url from a page under the same domain should succeed if the url is set up to answer such requests and the request has been authenticated and authorized to do it.. In other words, *it should work*, but I'm assuming here that you or somebody taken the precautions to make sure things are set up such that they *will* work. Has this API been verified to work with other clients or at all? Does your request really have everything the API needs? etc. – JayC May 21 '12 at 14:27
1

Here is your answer, enjoy : Are the PUT, DELETE, HEAD, etc methods available in most web browsers?

Per jQuery docs :

The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

What browser are you using?

Community
  • 1
  • 1
ilanco
  • 9,581
  • 4
  • 32
  • 37
0

I got the best solution for this problem

http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/

add entry in webconfig

  <modules runAllManagedModulesForAllRequests="true">
        <add name="CorsHttpModule" type="Thinktecture.IdentityModel.Http.Cors.IIS.CorsHttpModule"/>
    </modules>
Imran Rashid
  • 3,352
  • 4
  • 31
  • 41