Using OPTIONS instead of GET for fetching Backbone JS model data

Currently, I am attempting to retrieve data from a REST endpoint with the help of a model. Below is the code snippet that I am using:

professors: function(id) {
  professor = new ProfessorModel({
    id: id
  });

  professor.fetch({
    headers: {
      'HTTP_ACCESS_TOKEN': document.cookie
    },

    success: function(model, response, options) {
      AppController.showView(new ProfessorView({model: model}));
    },

    error: function(model, response, options) {
      AppController.showView(new ErrorView({
        statusCode: response.status,
        errorMessage: response.statusText
      }));
    }
  });
}

Unexpectedly, the REST endpoint is indicating that the fetch operation is utilizing OPTIONS instead of GET.

Although I attempted following this solution, it did not yield any results. CORS has already been enabled on my endpoint and the Backbone.enableHTTP option also failed to resolve the issue.

Upon examining the Backbone source, I was unable to identify any reference to it using OPTIONS for requests. Does anyone have any insights or suggestions regarding this matter?

Answer №1

When making a request, the OPTIONS method is triggered by the use of a custom HTTP header called 'HTTP_ACCESS_TOKEN': document.cookie. This behavior is fundamental to the XMLHttpRequest functionality.

Note that this behavior is not specific to Backbone framework, hence why it may not be explicitly mentioned in its source code.

The solution you referenced is indeed accurate. To address this issue, ensure that your server is configured to handle and respond correctly to the OPTIONS request.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to continuously loop and gradually fade the same image URL using JavaScript?

I have a dynamic image stored on my web server at example.com/webcam.jpg that is continuously updated by the server. My goal is to display this image on a static HTML page with a looping effect that smoothly transitions from the previous image to the upda ...

Is it possible to declare variables using the "this" keyword?

Consider the scenario where this.x=5 is declared and assess the accessibility of all relevant places. <script> $(document).ready(function(){ $("button").click(function(){ this.x=!this.x; $("#div1").fadeTo(400,this.x ? 0.4 : 1); }); }); & ...

invoking a function with a callback within a loop

I need to execute window.resolveLocalFileSystemURI(file,success,fail) within a for loop where different file entries are passed. The goal is to only return the resolved entries in an array once all entries have been successfully retrieved. function resolv ...

What is preventing the function from waiting for the promise to be resolved?

I am encountering an issue with the code snippet below. The control does not wait for the HTTP promise to be resolved before returning a string from the method, and I can see that the returned object is "method" in the switch statement. Can someone please ...

Sending data between two elements when a jQuery event is triggered

As a JavaScript beginner, I am facing an issue where I need to push data from an h1 tag to a textarea. My website is built using WooCommerce and when a visitor clicks on a product, a chat box with the product title opens. Currently, I have successfully p ...

Initiating a AJAX/prototype reset function

I have a question related to AJAX and prototype. Currently, I have an AJAX call in the onclick event inline which needs to be moved out of there. The code looks like this: onclick="var pn = $('yards').value; $('inventory').update(&apos ...

Is it possible to integrate external search functionality with Vuetify's data table component

I am currently working with the v-data-table component from Vuetify, which comes with a default filter bar in its properties. This table retrieves data from a local JSON file. The issue arises when I have another external component, a search bar created u ...

How to extract a subset of data from an existing object and create a new object in Vue JS

My latest project involves creating a search app to find products. I have implemented a PHP script that returns results in JSON format when a keyword is submitted. The data retrieval is done using axios. The challenge I am facing is with handling the disp ...

AngularJS implementation for a confirmation dialog with data

I need help creating a confirmation dialog box for user action verification. Here's the situation: I have a table with multiple events, and users can choose to delete an event. This is how the table is structured: <tbody> <tr ng-repeat= ...

Ending a timer from a different function in a React component

Currently, I am delving into the world of React and attempting to create a timer component. While I have successfully implemented the start function for my timer, I am now faced with the challenge of stopping the timer using an onclick handler from another ...

After consolidating buffer geometries, adjusting the transparency/opacity of the shapes is not an option for me

I've been working on a model with multiple boxes and trying to optimize draw calls by using buffer geometry merger. However, I'm facing an issue where I can't change the opacity of geometries after merging. Here are the things I've tri ...

Dealing with a variety of AJAX requests

After implementing AJAX to retrieve JSON data from multiple URLs and store them in separate arrays, I encountered an unexpected issue. Take a look at the code snippet below: var var1 = $.ajax({ url: FEED1, dataType: 'jsonp', crossDom ...

Unable to view HTML without an internet connection

I have encountered an issue where my files work fine when uploaded to an online server, but do not work when accessed locally offline. An error message about a cross-origin issue appears. How can I solve this problem? Error message: Security Error: Conte ...

Prefer using callback functions over setTimeout

The code snippet below is currently functioning properly: // Retrieve photos from a file and display the initial photo $.ajax({ type: "GET", url: "photos_gps.json", success: initialPhoto, error: handleError }); function initialPhoto(data) ...

The functionality of Nuxt's asyncData is restricted when attempting to access data from authorized express routes

Setting up an online store. I began with the products, which can be pulled without authorization but require it for editing. The process is smooth so far, probably because it's happening on the client side where authentication information is included ...

Unable to find module reference "three" at 137

Returning to an older project, I realized that nothing was loading. When I checked the console log, this is what I found: Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../". In my ...

AngularJS does not automatically generate input elements for editing purposes

Trying to make real-time edits to an element by triggering a function on ng-click using AngularJS. My HTML code: <div class="row question">{{questions.1.name}} <a href="" class="glyphicon glyphicon-pencil" ng-click="editQuestion(questions.1.name ...

Try utilizing a variety of background hues for uib progressbars

Looking to incorporate the ui-bootstrap progressbar into my template in two different colors, background included. My initial idea was to stack two progress bars on top of each other, but it ended up looking too obvious and messy, especially in the corner ...

Is it possible to automate the firing of setTimeout events using WebDriver?

Looking to test pages with numerous setTimeout functions, I'm searching for a way to expedite the code execution upon page load rather than waiting for it to run on its own. One idea is to inject custom JavaScript like this into the page before evalu ...

What steps are involved in creating a video playlist with YouTube videos?

Is there a way to create a dynamic video playlist that supports embedded YouTube videos without refreshing the page? If a user clicks on another video, I want the video to change dynamically. You can check out this for an example. Do jPlayer, Video.js, Fl ...