无法通过Jquery Ajax调用加载本地.xml文件 [英] Not able to load local .xml file through Jquery ajax call

查看:105
本文介绍了无法通过Jquery Ajax调用加载本地.xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在本地计算机上制作一个示例Web应用程序.我想对本地计算机上的.xml文件进行ajax调用.

I am making a sample web application on my local machine. I want to make ajax call to an .xml file which is on my local machine.

它根本无法在任何浏览器中使用. 当我尝试在Chrome的网络"标签中查看时,它显示XMLHttpRequest cannot load file:///D:/somefolder/finishers.xml?_=1392713504397.所请求的资源上没有'Access-Control-Allow-Origin'标头.因此,不允许访问原始空".

It is not working in any browsers at all. When i try to see in the Network tab of Chrome it display that XMLHttpRequest cannot load file:///D:/somefolder/finishers.xml?_=1392713504397. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

这可能是重复的问题,但我是Jquery的新手. 下面是我的代码.

May be this is possible duplicate question, but I am new to Jquery. Below is my code.

$.ajax({
    url: "finishers.xml",
    cache: false,
    dataType: "xml",
    success: function(xml){}    
});

请帮助我如何解决此问题. 预先感谢.

Please help me how to resolve this. Thanks in advance.

推荐答案

这是因为您在本地计算机上运行代码(而不在Web服务器下运行).

This is because you run the code in the local machine (without running under a web server).

将您的代码放在网络服务器(如apache)下,然后重试.

Put your code under a web server(like apache) and try again.

这篇关于无法通过Jquery Ajax调用加载本地.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆