Reputation: 3
Well guys... I've tried lots to fix this problem, catching some solutions here and in others Sites... But i don't get the solution to this problem!
Well what's the real problem.. It's simple i have this code:
function refreshRadioStats()
{
jQuery.support.cors = true;
$.get('http://raphaleao.com/json', function(data){
var templateStats = '<span class="glyphicon glyphicon-music"></span> '+ j_lang[0] +
'<marquee><h4><i>'+data.musica_atual+'</i></h4></marquee><br>'+
'<span class="glyphicon glyphicon-headphones"></span> '+j_lang[1]+': <b>'+data.ouvintes_conectados+
'</b><br>'+
'<span class="glyphicon glyphicon-user"></span> '+j_lang[3]+': <b>'+locutor+'</b><br><br>'+
'<button type="button" class="btn btn-info" id="refreshstadistics" style="width:100%"><span class="glyphicon glyphicon-refresh"></span> '+ j_lang[2] +'</button>';
$('#resultse').append(templateStats);
},'json');
}
Ok, what's the problem? The problem is: The script apparently can't acess the website http://raphaleao.com/json and for this, doesn't work. The problem:
XMLHttpRequest cannot load http://raphaleao.com/json. The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin 'Stack don't allow me to post more than 2 links' is therefore not allowed access.
The script works, because i've tested with other site in JSON and works perfectly. I've already put this in web.config:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
And the same problem, could you guys help me with this?
I've get the fix Well, after try some things and @mattferderer opened my mind, i figured out what's going on with all this...
First i've removed the web.config side and leave only the header() function. Okay first problem fixed (lol);
And than, i've figured out why $.getJSON() don't load the informations of other website... It's simple, just add (at least i did it in PHP) this:
header('Content-Type: text/javascript');
In my case, the page is in format text/html, so $.getJSON() will not able to load all informations in that page!
Thanks guys and sorry for the terrible english!
Upvotes: 0
Views: 129
Reputation: 974
Try removing the access-control-allow-origin from your web.config since the problem is the access-control-allow-origin is being used twice. If you look in your Response Headers it shows this:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
X-Powered-By: PHP/5.5.11
Access-Control-Allow-Origin: *
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Date: Wed, 06 Apr 2016 14:43:54 GMT
Content-Length: 387
Upvotes: 1