The request method is options, not a post (existing StackExchange service does not help)

Before you say another message ( jQuery $ .ajax (), $ .post by sending "OPTIONS" as REQUEST_METHOD in Firefox ), yes, help, so.

I use the latest version of Chrome dev, and when I try to send a file to the remote video converter API, like this, it works (all in coffeescript). Call this code 1:

  json_string = getNewSignedParams()

  xhr = new XMLHttpRequest
  xhr.open('POST', some_url, true)
  xhr.setRequestHeader("Cache-Control", "no-cache")
  xhr.setRequestHeader("Content-Type", "application/octet-stream")
  xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
  xhr.setRequestHeader("X-File-Name", some_file.name || some_file.fileName)
  xhr.setRequestHeader("X-Query-Params", json_string)

  xhr.send some_file

The above value returns 200 and just works. But I have jQuery on the page, so I thought I would use it, so I have a higher version of jQuery like this. And let this code 2:

  $.ajax
    url:  some_url
    type: 'post'
    data: some_file
    processData: false 
    beforeSend: (xhr) ->
      xhr.setRequestHeader("Cache-Control", "no-cache")
      xhr.setRequestHeader("Content-Type", "application/octet-stream")
      xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
      xhr.setRequestHeader("X-File-Name", some_file.name || some_file.fileName)
      xhr.setRequestHeader("X-Query-Params", json_string)
    success: ->
      console.log 'success'

I get this 400 (failed request) saying that Origin is http://127.0.0.1:3000not allowed by Access-Control-Allow-Origin.

, 1 2 , , 1 2 , 2 400 Bad request!!

, 2, 400, , . , , , 2 !

: Chrome , , 2, "" . 1 "POST"

- , ?

+5
1

, -, : URL. , URL- , script, . .

+2

All Articles