Java脚本从URL获取XML

java script to get xml from url

本文关键字:获取 XML URL 脚本 Java      更新时间:2023-09-26

我正在编写一个js来从URL获取xml,但我没有得到任何回应。我做错了什么?

  $(document).ready(function () {
            $.ajax({
            type: "GET",
            url: "http://www.w3schools.com/xml/simple.xml",
            dataType: "xml",
            success: function(response)
                {
                    alert(response);
                }
        });

    });

http://jsfiddle.net/4bh0qpb1/1/

修复的第一个脚本语法错误 ("),但由于 CORS(跨源资源共享)策略,您无法使用 ajax 访问以下 url http://www.w3schools.com/xml/simple.xml

原因跨源请求被阻止:同源策略不允许在 http://www.w3schools.com/xml/simple.xml 读取远程资源。可以通过将资源移动到同一域或启用 CORS 来解决此问题。

你忘了用双引号结束网址参数"