


Configure Chrome to support local (file protocol) AJAX requests (graphic tutorial)
This article mainly introduces in detail how to configure Chrome to support local (file protocol) AJAX requests. It has certain reference value. Interested friends can refer to
What are the issues?
During the WEB development process, many times we write some simple demos instead of developing a complete project. Our common operations at this time are:
•Create a new folder
•Create the required files
•Complete the DEMO coding in Sublime (or other editor)
•Double-click the HTML file to run the demo directly in the browser
If there is an AJAX operation in the Demo at this time, the browser will report an error:
XMLHttpRequest cannot load file:///Users/iceStone/Documents /Learning/angular/demo/angular-moviecat/movie/view.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource .
The reason is very simple. The security policy of the browser (Webkit kernel) determines that applications accessed by the file protocol cannot use the XMLHttpRequest object. The error message also clearly states:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Cross origin requests Only supports protocols: http, data, chrome, chrome-extension, https, chrome-extension-resource
This operation is allowed in some browsers, such as Firefox browser, that is It is said that Filefox supports AJAX requests under the file protocol.
Solution
As my personal favorite Chrome, it is powerful, there is nothing to say, except that I can’t think of it, and there is almost nothing I can’t do, so Must and must be supported:
Windows:
•Set Chrome’s shortcut properties and add –allow-file after “target” -access-from-files, note there is a space in front of it, just reopen Chrome.
Mac:
•The browser can only be opened through the terminal: Open the terminal and enter the following command: open -a "Google Chrome” –args –disable-web-security and then you can block secure access [ –args: This parameter is optional]
Supplementary instructions
In the long run, you will definitely need to access your application through HTTP, so you need to configure HTTP server software. However, for some students who are just getting started, setting up an HTTP server (such as Apache, IIS, etc.) is cumbersome and prohibitive.
•There is nothing to say to students who use IDEs. Every IDE used for web development has a built-in http server, so there is no need to configure it separately.
•For students who like lightweight editors, such as Sublime Text, it does not have a built-in HTTP server by default
Next, I recommend a Sublime plug-in, Sublime Server, which can provide A static file HTTP server, the specific usage is as follows:
•Install Package Control (Sublime's plug-in management tool), which will not install its own Google
•Command Shift P or Ctrl Shift P to open the command Panel, enter Package Control: Install Package
•Wait for a moment (it will connect to the plug-in provider's server, which is relatively slow and may be behind the wall), search for SublimeServer
•After the installation is completed, use Tool → SublimeServer → Start SublimeServer
•Be sure to use Sublime by opening a folder, otherwise you will not be able to use SublimeServer normally.
•Open the HTML file and select View in SublimeServer in the right-click menu. At this time, you can access the file in the browser through HTTP.
•If this option is gray, it means that SublimeServer is not started. , Tool → SublimeServer → Start SublimeServer
So far, you can already use the HTTP server in Sublime.
Possible problems
If Start SublimeServer cannot be clicked, the current port 8080 may be occupied (SublimeServer uses port 8080 by default)
The solution is to open the configuration file and change the port to another port:
The following is my configuration:
{ "attempts": 5, "autorun": false, // 是否在启动Sublime时自动启动SublimeServer "defaultExtension": ".html", "interval": 500, "mimetypes": { "": "application/octet-stream", ".c": "text/plain", ".h": "text/plain", ".py": "text/plain" }, "port": 2016 // 端口号 }
Of course other editors also have similar plug-ins.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Simple implementation of AJAX paging effect (graphic tutorial)
When using frameworks such as Ajax or Easyui Json-lib processing solution (graphic tutorial)
Ajax realizes infinite loading of lists and secondary drop-down option effects
The above is the detailed content of Configure Chrome to support local (file protocol) AJAX requests (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Every application you run on Windows has a component program to update it. So if you are using Google Chrome or Google Earth, it will run a GoogleUpdate.exe application, check if an update is available, and then update it based on the settings. However, if you no longer see it and instead see a process updater.exe in the Task Manager of Windows 11/10, there is a reason for this. What is Updater.exe in Windows 11/10? Google has rolled out updates for all its apps like Google Earth, Google Drive, Chrome, etc. This update brings

crdownload is a chrome browser download cache file, which is a file that has not been downloaded; crdownload file is a temporary file format used to store files downloaded from the hard disk. It can help users protect file integrity when downloading files and avoid being damaged. Unexpected interruption or stoppage. CRDownload files can also be used to back up files, allowing users to save temporary copies of files; if an unexpected error occurs during downloading, CRDownload files can be used to restore downloaded files.

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

Chrome's inability to load plug-ins can be solved by checking whether the plug-in is installed correctly, disabling and enabling the plug-in, clearing the plug-in cache, updating the browser and plug-ins, checking the network connection, and trying to load the plug-in in incognito mode. The solution is as follows: 1. Check whether the plug-in has been installed correctly and reinstall it; 2. Disable and enable the plug-in, click the Disable button, and then click the Enable button again; 3. Clear the plug-in cache, select Advanced Options > Clear Browsing Data, check cache images and files and clear all cookies, click Clear Data.

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

What is the Chrome plug-in extension installation directory? Under normal circumstances, the default installation directory of Chrome plug-in extensions is as follows: 1. The default installation directory location of chrome plug-ins in windowsxp: C:\DocumentsandSettings\username\LocalSettings\ApplicationData\Google\Chrome\UserData\Default\Extensions2. chrome in windows7 The default installation directory location of the plug-in: C:\Users\username\AppData\Local\Google\Chrome\User

What should I do if the Google Chrome web page cannot be opened? Many friends like to use Google Chrome. Of course, some friends find that they cannot open web pages normally or the web pages open very slowly during use. So what should you do if you encounter this situation? Let’s take a look at the solution to the problem that Google Chrome web pages cannot be opened with the editor. Solution to the problem that the Google Chrome webpage cannot be opened. Method 1. In order to help players who have not passed the level yet, let us learn about the specific methods of solving the puzzle. First, right-click the network icon in the lower right corner and select "Network and Internet Settings." 2. Click "Ethernet" and then click "Change Adapter Options". 3. Click the "Properties" button. 4. Double-click to open i
