Why does my http://localhost CORS origin not work?

I am stuck with this CORS problem, even though I set the server (nginx/node.js) with the appropriate headers. I can see in Chrome Network pane -> Response Headers: Access-Control-Allow-Origin:http://localhost which should do the trick. Here’s the code that I now use to test: var xhr = new XMLHttpRequest(); xhr.onload = function() { console.log(‘xhr loaded’); }; … Read more

Why am I getting an OPTIONS request instead of a GET request?

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js” type=”text/javascript”></script> <script> $.get(“http://example.com/”, function(data) { alert(data); }); </script> it does an OPTIONS request to that URL, and then the callback is never called with anything. When it isn’t cross domain, it works fine. Shouldn’t jQuery just make the call with a <script> node and then do the callback when its loaded? I understand … Read more

Origin is not allowed by Access-Control-Allow-Origin

I’m making an Ajax.request to a remote PHP server in a Sencha Touch 2 application (wrapped in PhoneGap). The response from the server is the following: XMLHttpRequest cannot load http://nqatalog.negroesquisso.pt/login.php. Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin. How can I fix this problem? 18 Answers 18

How to read a local text file?

I’m trying to write a simple text file reader by creating a function that takes in the file’s path and converts each line of text into a char array, but it’s not working. function readTextFile() { var rawFile = new XMLHttpRequest(); rawFile.open(“GET”, “testing.txt”, true); rawFile.onreadystatechange = function() { if (rawFile.readyState === 4) { var allText … Read more

“Origin null is not allowed by Access-Control-Allow-Origin” error for request made by application running from a file:// URL

I’m developing a page that pulls images from Flickr and Panoramio via jQuery’s AJAX support. The Flickr side is working fine, but when I try to $.get(url, callback) from Panoramio, I see an error in Chrome’s console: XMLHttpRequest cannot load http://www.panoramio.com/wapi/data/get_photos?v=1&key=dummykey&tag=test&offset=0&length=20&callback=processImages&minx=-30&miny=0&maxx=0&maxy=150. Origin null is not allowed by Access-Control-Allow-Origin. If I query that URL from a … Read more

Send POST data using XMLHttpRequest

I’d like to send some data using an XMLHttpRequest in JavaScript. Say I have the following form in HTML: <form name=”inputform” action=”somewhere” method=”post”> <input type=”hidden” value=”person” name=”user”> <input type=”hidden” value=”password” name=”pwd”> <input type=”hidden” value=”place” name=”organization”> <input type=”hidden” value=”key” name=”requiredkey”> </form> How can I write the equivalent using an XMLHttpRequest in JavaScript? 13 s 13 The … Read more

Access-Control-Allow-Origin Multiple Origin Domains?

Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header? I’m aware of the *, but it is too open. I really want to allow just a couple domains. As an example, something like this: Access-Control-Allow-Origin: http://domain1.example, http://domain2.example I have tried the above code but it does not seem to work in Firefox. … Read more

How can I upload files asynchronously with jQuery?

I would like to upload a file asynchronously with jQuery. $(document).ready(function () { $(“#uploadbutton”).click(function () { var filename = $(“#file”).val(); $.ajax({ type: “POST”, url: “addFile.do”, enctype: ‘multipart/form-data’, data: { file: filename }, success: function () { alert(“Data Uploaded: “); } }); }); }); <script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js”></script> <span>File</span> <input type=”file” id=”file” name=”file” size=”10″/> <input id=”uploadbutton” type=”button” value=”Upload”/> … Read more