通过https上的ajax加载XML文件

时间:2014-08-08 12:24:30

标签: jquery ajax xml https

我尝试加载存储在:

中的ajax文件
/folder/folder/somefile.xml

脚本在索引中调用,因此我的导演结构如下所示:

  • 的index.html
      • somefile.xml

我的网站只有https,当我执行该功能时,它会给我这个错误:

  

https://somepage.com/some/long/url上的页面是通过HTTPS加载的,但显示来自https://samepage.com的不安全内容,此内容也应通过HTTPS加载。

这是我的ajax电话:

$.ajax({
        type        : "GET",
        url         : "folder/folder/somefile.xml",
        dataType    : "xml",
        success     : function(xml){
           //do some crazy stuff     
        },
        error : function(){
           alert("error");
        }

如何强制脚本使用https?是否可以通过相对路径来做到这一点?

修改

解释非常复杂。但这是我的错。客户得到了一个cms,cms将文件夹解析成他们自己的结构。我需要的只是“folder / folder / somefile.xml”之前的“/”

1 个答案:

答案 0 :(得分:1)

嗯......非常奇怪,因为它应该有用......

这是我的工作示例:

<强> HTML

<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.js"></script>
</head>
<body>
<script type="text/javascript">
    $(document).ready(function() {
        $.ajax({
                type        : "GET",
                url         : "v1/somexml.xml",
                dataType    : "xml",
                success     : function(xml){
                    alert(xml)
                },
                error : function(){
                    alert("error");
                }
        });
    });
</script>
</body>
</html>

<强> XML

<companies>
    <company name="1" imageurl="logo">
    <certification> Certified Best Employer </certification>
    <employee> 5,0000 </employee>
    <industry> Risk Services </industry>
    <html_url> http://www.google.com </html_url>
    </company>

    <company name="2" imageurl="logo">
    <certification> Certified Best Employer </certification>
    <employee> 5,0000 </employee>
    <industry> Risk Services </industry>
    <html_url> http://www.google.com </html_url>
    </company>

    <company name="3" imageurl="logo">
    <certification> Certified Best Employer </certification>
    <employee> 5,0000 </employee>
    <industry> Risk Services </industry>
    <html_url> http://www.google.com </html_url>
    </company>
</companies>

我可以通过HTTP或HTTPS运行它...结果是一样的,我可以访问XML。与你的例子有什么不同?如何将jQuery添加到页面?