开发者

Jquery get xml file

I'm trying to download a XML file via a jquery .get() request. unfortunately the return开发者_Go百科ed 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">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<body>
    Test sportevai<br/>
<script type="text/javascript" src="http://risultati.sportevai.it/sportevai_widget.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜