Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket.io cross-domain issue - Origin is not allowed by Access-Control-Allow-Origin
    primarykey
    data
    text
    <p>I have a website at a url (example.com) and am using node.js/socket.io to pass JSON into my webpage. I'm currently receiving an error: "XMLHttpRequest cannot load <a href="http://example.com:12003/socket.io/1//897026922693503087/?disconnect=1" rel="nofollow">http://example.com:12003/socket.io/1//897026922693503087/?disconnect=1</a>. Origin <a href="http://example.com" rel="nofollow">http://example.com</a> is not allowed by Access-Control-Allow-Origin."</p> <p>My node code looks like the following:</p> <pre><code> var http = require('http'); var mysqlClient = require('mysql').createClient({'user':'root','password':'XXXXXXXX'}); mysqlClient.query('USE myDBName'); var mysqlData; setInterval(function(){ mysqlClient.query( 'SELECT number, page_id FROM dbTableName', function selectCb(err, results, fields) { if (err) { throw err; } mysqlData = []; for(var i = 0; i &lt; results.length; i++){ mysqlData[i] = results[i]; } }); }, 1000); var io = require('socket.io').listen(12003); io.sockets.on('connection', function(client) { console.log("New Connection: ", client.id); //log new connection client.emit('connection', client.id);//custom emit to let site know its connected client.on("requestNewData", function(data){ client.emit('init', JSON.stringify(mysqlData)); }); client.on('disconnect', function() { console.log("Disconnected: ", client.id); }); }); </code></pre> <p>I've tried this line of code to fix the issue with no success:</p> <pre><code> var io = require('socket.io').listen(12003, {origins: '*:*'}); </code></pre> <p>I'm running on an Amazon EC2 with Ubuntu Ocelot. My client side code is:</p> <pre><code> &lt;script src="http://example.com:12003/socket.io/socket.io.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var socket = io.connect('http://example.com:12003'); socket.emit("requestNewData", {"nothing":"here"}); ... </code></pre> <p>Since I'm just using a socket I don't think I can use 'Access-Control-Allow-Origin' : '*' in my node code. Any help would be greatly appreciated. The error I'm receiving is only on Chrome - from my understanding Chrome is more restrictive about cross-domain connections...</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload