views:

17

answers:

1

I'm trying to download a XML file via a jquery .get() request. unfortunately the returned data seems to be empty (0 length string), even if the browser downloads correctly the XML file (the request returns a 200 http code via firebug)

here's my code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt;
<body>
    Test sportevai<br/>
<script type="text/javascript" src="http://risultati.sportevai.it/sportevai_widget.js"&gt;&lt;/script&gt;
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"&gt;&lt;/script&gt;
<script type="text/javascript">
    $(document).ready(function(){

        $.get('http://servername.com/xml/10225.xml', function(data) {
            alert(data.length);
        $('.xcf').html(data);

        });

        });
</script>
<div id="xcf">div response</div>
</body>
</html>
+1  A: 

You can't get XML from a remote domain like this, you can only fetch JSONP. The same-origin policy prevents it. What will happen is exactly what you're experiencing, everything will appear normal except that the response will be empty.

You'll have to proxy the request through your domain/site or go a different route altogether, if you have to use XML. If you can fetch JSONP, you can do this strictly in JavaScript.

Nick Craver