This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15322|Reply: 1

[Jquery] XMLHttpRequest cannot load ''. No 'Access-Control-Allow-Origin'

[Copy link]
Posted on 9/27/2015 10:48:47 PM | | | |


Mistake:
XMLHttpRequest cannot load  ''. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' ' is therefore not allowed access.
Cause: Javascrip{filter}t also gets this error when accessing local files. For security reasons, browsers do not allow Javascrip{filter}t to access local files.
Solution:

Chrome does not support local Ajax requests, and this problem occurs when I access .json file in a .html file, which means that this .html file cannot be loaded at this time.

Solution

Open the Chrome shortcut's properties settings:
Right-click on the Chrome browser shortcut and select "Properties",
Add "--allow-file-access-from-files" to "Target", notice a space in front of it,
Just restart your Chrome browser.





Previous:What is the origin of the dark clouds that broke out of Ctrip and other leaks?
Next:js intercepts the last one. can be used to judge the IP segment range
Posted on 12/6/2015 4:18:33 PM |
<html>
<head>
    <title>title</title>
    <scrip{filter}t src="http://code.jquery.com/jquery-1.7.1.min.js"></scrip{filter}t>
    <scrip{filter}t>
        $.ajax({
            url:"http://www.test.com/gpsApi.php?lat=22.502412986242&lng=113.93832783228",
            type:'GET',
            dataType:'JSONP',
            success: function(data){
                $('body').append( "Name: " + data );
            }
        });
    </scrip{filter}t>
</head>
<body>
Test Ajax cross-domain questions
</body>
</html>

Use the jsonp format, such as ajax request parameter dataType: 'JSONP' in jquery.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com