Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:12:02+00:00 2026-06-12T20:12:02+00:00

Hello I need to make json requests from Backbone to an API (I have

  • 0

Hello I need to make json requests from Backbone to an API (I have control over server-side)..
I keep getting the Access-Control-Allow-Origin, although response headers looks fine.

Here are Nginx settings:

location / {
     if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
     }
     if ($request_method = 'POST') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }
     if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }
passenger_enabled on;
} 

here are the request / response headers from console:

Request headers
DNT: 1
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/534.57.7 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.7
Accept: */*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript
Referer: http://<address>/

Response Headers
Access-Control-Request-Method: *
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.14
Transfer-Encoding: Identity
Status: 200
Connection: keep-alive
X-Request-Id: 2917f130c8699182ee9cdc047c1926fe
X-UA-Compatible: IE=Edge,chrome=1
X-Runtime: 0.455212
Server: nginx/1.2.2 + Phusion Passenger 3.0.14 (mod_rails/mod_rack)
Etag: "346cee46bab7061e866fa064df95c845"
Content-Type: text/html; charset=utf-8
Access-Control-Allow-Origin: *
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: _y_app_session=BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJWE2Zjg3YWQ0NDFjZWNiM2VmNTg2ZDhiYmIyOGFlYmIwBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMUxBSzFKTDJQWG1sa2dhbXRLM2ptQmxjenRkZEdJeVh1MDFhaUVuaXE1dFE9BjsARkkiCmZsYXNoBjsARm86JUFjdGlvbkRpc3BhdGNoOjpGbGFzaDo6Rmxhc2hIYXNoCToKQHVzZWRvOghTZXQGOgpAaGFzaHsAOgxAY2xvc2VkRjoNQGZsYXNoZXN7CDoLbm90aWNlMDoLZXJyb3JzMDoKZXJyb3IwOglAbm93MA%3D%3D--648ffcb1b2869f1da57773459307ca1ac5fb8bfb; path=/; HttpOnly
Access-Control-Allow-Headers: *

* UPDATE *

I am currently using http://github.com/yaoweibin/nginx_cross_origin_module and it allows me to make requests from console.

I have set up the nginx as in instructions in the repo above.

    cors on;
    cors_max_age     3600;
    cors_origin_list unbounded;
    cors_method_list GET HEAD PUT POST;
    cors_header_list unbounded;

    server {
     ## Server stuff.. 
     # passenger stuff
   }

So I can do:

 var xhr = new XMLHttpRequest()
 xhr.open('GET', 'http://www.api.com/plots.json')
 xhr.send();

When I do fetch via Backbone with the model that has ‘http://www.api.com/plots.json&#8217; as url I get Same origin errors.

** UPDATE **

So I switched to more_set_headers and can do .fetch() now… Still cannot make POST or do collection.create();

Here is the latest Nginx setup:

server {

              listen 80;
              server_name api.app.com;
              root /home/ubuntu/app/current/public;
              passenger_enabled on;


    location / {
        if ($request_method = 'OPTIONS') {
             more_set_headers 'Access-Control-Allow-Origin: *';
             more_set_headers "Access-Control-Allow-Methods: OPTIONS, GET, PUT, DELETE, POST";
             more_set_headers "Access-Control-Allow-Headers:  x-requested-with";
             more_set_headers "Access-Control-Max-Age: 1728000";
             more_set_headers 'Content-Type: text/plain; charset=UTF-8';
             more_set_headers 'application/json; charset=utf-8';
             return 200;
            }

          if ($request_method = 'POST') {
           more_set_headers "Access-Control-Allow-Origin: http://vidoai.com";
           more_set_headers "Access-Control-Allow-Methods: GET, POST, OPTIONS";
           more_set_headers 'Access-Control-Allow-Headers: DNT, X-Mx-ReqToken, Keep-Alive,  User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type';
           more_set_headers 'Content-Type: application/json, text/javascript,  */*';
         }


passenger_enabled on;
    }


        if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
           return 444;  # block requests that Rails doesn't handle
          }





}

What am I missing??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:12:05+00:00Added an answer on June 12, 2026 at 8:12 pm

    In this line:

    if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {}
    

    You should add OPTIONS too because that is what Backbone would be using probably and you have it defined in your location as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I need to make a chart like this : http://www.xe.com/currencycharts/?from=USD}&to=EUR Should I use
I need to know how i can make a string like hello to Hello
Hello i need to create a progressView when i load data from my webservice.
Hello I need to have multiple language support of my django admin application.I can
hello i need to do the following: move a node from jstree to another
Hello I need to remake some old C++Builder (6) project and make it for
I need to make the json params like below. Final output should be, {submissionTime:\/Date(1331549630849)\/,
Hello guys I need to make a simple android quiz. Well what I've done
Hello, thanks for reading my question. I have a string that I need to
Hello I need to make a wordpress slideshow. I need the loop to list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.