What is the process for retrieving file content from box.com through an ajax request?

I'm attempting to retrieve the content of a CSS file from box.com using a direct link and add it to the head tag, but unfortunately, my current method is not successful.

$.ajax({                
        url: "https://app.box.com/shared/static/" + file_hash + ".css",                
        data: { client_id : '6guib1cgnk8uk2kdre45rjg7lt2xayegl94' },
        type: "GET",
        async: false,
        crossDomain: true,
        dataType: "text",
        success: function (data) {
          $("<style></style>").appendTo("head").html(data);
        },
        error: function (error) {
            console.log(error);
        }
    }
);

Could someone offer guidance on how to resolve this issue?

Upon encountering an error, the response object looks like this:

Object
abort: function ( statusText ) {
always: function () {
complete: function () {
done: function () {
error: function () {
fail: function () {
getAllResponseHeaders: function () {
getResponseHeader: function ( key ) {
overrideMimeType: function ( type ) {
pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
progress: function () {
promise: function ( obj ) {
readyState: 0
responseText: undefined
setRequestHeader: function ( name, value ) {
state: function () {
status: 0
statusCode: function ( map ) {
statusText: "error"
success: function () {
then: function ( /* fnDone, fnFail, fnProgress */ )

Answer №1

Upon running your provided code, I encountered the following error message:

When attempting to load , the XMLHttpRequest displays an error indicating that no 'Access-Control-Allow-Origin' header is found on the requested resource. As a result, access from 'https://example.com' is restricted.

The issue at hand arises from making a cross-domain (CORS) request, which is typically limited by JavaScript to resources within the same domain unless expressly permitted by the target application.

By default, Box does not support CORS requests; however, it can be enabled for specific applications as discussed in this post: Access Control Allow Origin Error. To proceed, reach out to Box support outlining your intended use case.

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

Clicking on links will open them in a separate tab, ensuring that only the new tab

Is there a way to open a new tab or popup window, and have it update the existing tab or window whenever the original source link is clicked again? The current behavior of continuously opening new tabs isn't what I was hoping for. ...

Where should AJAX-related content be placed within a hyperlink?

When needing a link to contain information for an AJAX call, where is the correct place to include the info? I have typically placed it in the rel attribute, but after reviewing the documentation for rel, it appears that this may not be the right location ...

Prevent premature termination of slow HTTP requests in Node.js/Express server

Having an issue with long duration http requests in my React/Nodejs application. Whenever a request takes more than 4 minutes to respond, it gets aborted before reaching the client. Could there be a timeout setting for requests or something else I am overl ...

What is the concept of nested includes in sequelize?

Is it possible to perform a nested include in Sequelize? I have a table called products that has a one-to-many relationship with comments, and the comments table has a many-to-one relationship with the users table. Each comment has a user_id and product_id ...

Flipping back and forth between two images within a single HTML file

I am looking to customize my top navbar for two different webpages, the root URL (/) and firstpage (/firstpage). The top navbar contains 2 images that I want to switch based on which page the user is currently on. Here is the code snippet: <img class=" ...

Learn how to connect a Firebase account that was created using a phone number

✅ I have successfully implemented the feature that allows users to update their profile with a mobile number using verifyPhoneNumber and update currentUser.updatePhoneNumber ❌ However, a problem arises when a new user attempts to sign in with a phone ...

I'm having trouble with my react-big-calendar not updating when I switch between day, month, or week views -

Why won't my calendar change to the week view when I click on that section? https://i.stack.imgur.com/gh2aO.png In the screenshot above, my default view is set to month, but when I attempt to switch to week, it only highlights the option without cha ...

I am unable to retrieve all the selected checkbox values from the pug template in Express

If you are following the Express MDN tutorial here, you might have encountered an issue with pulling in checkbox values from Pug. In the tutorial, req.body.genre is expected to return an array of selected values from a form. The code snippet for this func ...

Interactive back button for seamless navigation back to the originating modal

This website is built on Bootstrap 4. As I develop this site, there are a total of 17 different modals. Specific words in each modal are linked to other modals for additional information. However, getting back to the previous modal requires closing the ...

Issue: [AppRoutes] is not recognized as a valid <Route> component

Currently diving into React-Router with guidance from this helpful tutorial: https://blog.logrocket.com/complete-guide-authentication-with-react-router-v6/ Here's a snippet from my App.jsx: import { Route, createBrowserRouter, createRoutesFromE ...

What causes the return value of an ajax request to be undefined when using setTimeout? How can this issue be resolved?

When the HTML body loads, I have two separate AJAX functions that need to be called. These functions should operate at different time intervals for different types of chat in order to distribute the server workload effectively. (No JQuery, please) functio ...

Using AJAX to submit a PHP form

Is there a way to activate the PHP post to database script without needing to refresh the page, similar to how it works with traditional PHP self? ...

The equivalent of the $.curCSS method in jQuery version 1.10 is as follows:

While working with a library called mcdropdown from http://www.givainc.com/labs/, I encountered an issue with the $.curCSS method. The latest version of jQuery no longer supports this method and suggests using $().css instead. Following the documentation, ...

How can I designate a controller and action for Ajax pagination using Kaminari?

Currently, I've integrated the Kaminari gem into my ruby on rails application and I must say, it's a significant upgrade from will_paginate. It offers a cleaner and more versatile solution. However, I'm facing an issue with AJAX pagination. ...

Incorporate JavaScript to dynamically fetch image filenames from a directory and store them in an array

By clicking a button, retrieve the names of images from a folder and store them in an array using jQuery. I currently have a script that adds images to the body. In the directory images2, there are 20 images stored. The folder images2 is located in my i ...

The current date object in JavaScript will only display the year or a combination of the month and

$scope.articles = [ { link: "http://google.com", source: "Google", title: "hello", "date": new Date(2008, 4, 15) }, ]; <tbody> <tr ng-repeat = "article in articles | orderBy:sortType:sortReverse | filter:searchArticle ...

What is the process for loading Syntax Highlighter on pages with pre tags?

As a Blogger, I often find myself in need of demonstrating codes on my blog. To achieve this, I have been using a Syntax Highlighter developed by Alex Gorbatchev. However, a recurring issue I face is that the files load on every single page of my blog, cau ...

Obtain geographic information using a JSON fetch from a map

I am facing an issue while integrating Laravel API data into React. Although I can see the JSON data in the console after fetching it, I encounter an error when I try to display it in a table for listing. The error states that my .map function is not recog ...

Display not refreshing as expected

Just to clarify, I am new to working with Angular. I've been struggling for the past few hours to toggle authentication in my service by clicking a button that should display user information or a sign-in image based on whether the authentication is ...

Unable to retrieve object element in angular

weatherApp.controller('forecastController', ['$scope','weatherService','$resource','$log', function($scope,weatherService,$resource,$log){ var cnto =3; $scope.forecastholder = weatherService.holder; $scope ...