3
is it possible to read an xml in another domain? ex:
http://mfmradio.fr/winradio/prog10.xml?player201507291645
did the code:
<script type="text/javascript">
var i;
var timer,timeout2;
$(document).ready(function(){
LoadProg = function(timeout){
timeout2 = timeout;
$.ajax({
cache: "false",
type: "POST",
url: 'http://mfmradio.fr/winradio/prog10.xml?player201507291645',
dataType: 'xml',
success: function(xml, textStatus, XMLHttpRequest){
$('#title-list').html('');
var pochetteEnCours = $(xml).find('morceau:eq(0)').find('pochette').text();
var pochetteEnCours = pochetteEnCours.replace(/^\s+|\s+$/g,"");
$('<li class="pochette"><\/li>').html(
pochette
).appendTo('#title-list');
$('<li class="artiste"><\/li>').html(
$(xml).find('morceau:eq(0)').find('chanteur').text()
).appendTo('#title-list');
$('<li class="titre"><\/li>').html(
$(xml).find('morceau:eq(0)').find('chanson').text()
).appendTo('#title-list');
var musiqueEnCours = "J'écoute " + $(xml).find('morceau:eq(0)').find('chanteur').text() + " - " + $(xml).find('morceau:eq(0)').find('chanson').text();
$('<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?via=MFMRadio&text='+musiqueEnCours+'&count=horizontal" style = "width: 110px; hauteur: 20px; position:absolute; margin-top:80px; margin-left:190px;"></iframe>').appendTo('#button_twitter');
// Last Titles
$('#last-titles-list').html('');
$('prog morceau:gt(0):lt(4)', xml).each(function(){
var pochetteArchive = $(this).find('pochette').text();
var pochetteArchive = pochetteArchive.replace(/^\s+|\s+$/g,"");
if( (typeof( pochetteArchive ) != "undefined") && (pochetteArchive != '') ){
var pochette = '<img src="' + $(this).find('pochette').text() +'"/>';
}else{
var pochette = '<img src="/media/pochette.png"/>';
}
$('<li><\/li>').append(
$('<span class="pochette"><\/span>').html(pochette)
).append(
$('<span class="artiste"><\/span>').html($(this).find('chanteur').text())
).append(
$('<span class="titre"><\/span>').html($(this).find('chanson').text())
).appendTo('#last-titles-list');
});
}
});
timer = setTimeout("LoadProg(timeout2)", timeout);
}
});
$(document).ready(function(){
LoadProg(20000);
});
</script>
But returns the error:
XMLHttpRequest cannot load http://mfmradio.fr/winradio/prog10.xml?player201507291645. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.doratiotto.com.br' is therefore not allowed access.
As I do not have access to the domain I could not for example create a crossdomain.xml
already tried jquery $.getJson?
– Marconi
It won’t. Unless you use a language like PHP to read an external file. The same origin policy will block, and you will not be able to read that file that is on external domain
– Wallace Maxters