Can't load a file in ajax from my pc

2019-08-29 07:06发布

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条回答
聊天终结者
2楼-- · 2019-08-29 07:47

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.
查看更多
登录 后发表回答