无法从我的PC加载Ajax文件

编程入门 行业动态 更新时间:2024-10-28 04:29:59
本文介绍了无法从我的PC加载Ajax文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要从我的PC中以ajax加载xml文件,但是该脚本在当前状态下不起作用(不知道为什么).这是我所拥有的:

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); } });

推荐答案

此处存在多个问题:

  • 文件URL不使用确切的窗口路径名 c:\ xxx .它们必须是实际的文件URL.
  • 所有浏览器均会阻止跨源" ajax请求.跨源请求是URL的第一部分(协议,端口,域)与所加载页面的第一部分不同的任何请求.这可以解释为什么它使用相对路径而不是绝对路径.您尝试使用的URL的第一部分可能不同于您从中加载页面的URL的第一部分.尝试此操作时页面的URL是什么?
  • 出于安全原因,某些浏览器不允许您从本地磁盘加载任何文件,即使HTML文件是本地文件,甚至是原始文件也是如此.
  • File URLs don't use the exact window path names c:\xxx. They have to be actual file URLs.
  • 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?
  • 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.
  • 更多推荐

    无法从我的PC加载Ajax文件

    本文发布于:2023-11-02 03:24:58,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1551238.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:加载   文件   PC   Ajax

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!