Can't load a file in ajax from my pc

谁都会走 提交于 2019-12-12 05:29:39

问题


I need to load a xml file from my pc in ajax, but the script it's not working at it's current state(no clue why). Here is what i have:

$.ajax({
    type: "GET",
    url : 'file:///C:/xampp/htdocs/files/license/index_skin.xml',
    dataType: "text",
    success : function (data) {
        $("#txarea").val(data);
    }
});

回答1:


There are multiple issues in play here:

  1. File URLs don't use the exact window path names c:\xxx. They have to be actual file URLs.
  2. All browsers prevent "cross origin" ajax requests. A cross origin request is any request where the first part of the URL (protocol, port, domain) are not the same as that of the page that is loaded. This may explain why it works with a relative path, but not an absolute path. Perhaps the first part of the URL you are trying to use is different than the first part of the URL you loaded the page from. What is the page URL when you are trying this?
  3. Some browsers won't let you load any file from your local disk (for security reasons) even if the HTML file is local and even if the origin is the same.


来源:https://stackoverflow.com/questions/27137687/cant-load-a-file-in-ajax-from-my-pc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!