8

I'm loading my script on a domain and sending some data with POST and the use of Ext.Ajax.request() to that same domain.

Somehow the dev-tools show me, that there is a failed OPTIONS request.

Request URL : myurl-internal.com:8090/some/rest/api.php

Request Headers
  Access-Control-Request-Headers : origin, x-requested-with, content-type
  Access-Control-Request-Method  : POST
  Origin                         : http://myurl-internal.com:8090

It's both HTTP and not HTTPS. Same port, same host ... I don't know why it's doing this. The server can't handle such stuff and so the request fails and the whole system stops working.

miken32
  • 42,008
  • 16
  • 111
  • 154
K..
  • 4,044
  • 6
  • 40
  • 85

3 Answers3

10

It's not really specific to Ext JS -- see these related threads across other frameworks. It's the server properly enforcing the CORS standard:

for HTTP request methods that can cause side-effects on user data (in particular, for HTTP methods other than GET, or for POST usage with certain MIME types), the specification mandates that browsers “preflight” the request, soliciting supported methods from the server with an HTTP OPTIONS request header, and then, upon “approval” from the server, sending the actual request with the actual HTTP request method.

If you're going to use CORS, you need to be able to either properly handle or ignore these requests on the server. Ext JS itself doesn't care about the OPTIONS requests -- you'll receive the responses as expected, but unless you do something with them they'll just be ignored (assuming the server actually allows whatever you're trying to do).

If you are NOT intending to use CORS (which sounds like you aren't purposefully going cross-domain) then you need to figure out why the server thinks the originating domain is different (I'm not sure about that). You could also bypass CORS altogether by using JsonP (via Ext's JsonP proxy).

Community
  • 1
  • 1
Brian Moeskau
  • 20,103
  • 8
  • 71
  • 73
  • The problem seemed to be, that my URL was without `http://` at the begining. When I changed it, the `OPTIONS` request vanished... – K.. Sep 27 '12 at 08:48
3

Use relative url instead of absolute, then you will get expected result.

3

use before request

Ext.Ajax.useDefaultXhrHeader = false
RaviPatidar
  • 1,438
  • 1
  • 18
  • 29