helloxielan 2015-06-18 14:52 采纳率: 0%
浏览 46

无法加载ajax

I can't display my .txt file in html page (local), with .load. File is in the same folder with .js.

$(function(){  
    $("#div1").load("text.txt");  
}); 
  • 写回答

1条回答 默认 最新

  • weixin_33709609 2015-06-18 16:24
    关注

    Last time I checked, opening local files with local HTML will work in IE but not Chrome, Firefox, etc. due to security reasons.

    If you're comfortable with HTML and javascript and want to run things locally and manipulate local files, have a look at HTML Applications or .hta. It's pretty neat.

    Here is Microsoft's documentation and here is an example with Javascript.

    To avoid the Windows system ActiveX warnings, your program should run under an .hta envelope, ie, as an application (like an .exe file).

    The following code opens your application under the .hta "umbrella", in a window of your sizing (in the example: 1030 x 95 pix) centered in the lateral direction and low on the screen. It does not allow scrolling. Make a text file and save it under YourChoiceOfName.hta

    <HTML>
    <HEAD>
    <script language="javascript" type="text/javascript">
      function Set(){   // this limits the size of the window opened and positions it
        var l=(screen.width/2 - 515); // centre - half the window width
        var t=(screen.height-130); // where you want it vertically
        self.moveTo(l,t);
        self.resizeTo('1030','95'); // as you can see, this example opens a longish but squat window, near the task-bar
      }
    </script>
    <TITLE>BlahBlah-The Progam</TITLE>
    <HTA:APPLICATION ID="BlahBlah-App"
        BORDER="thin"
        INNERBORDER="no"
        SCROLL="no" 
        SCROLLFLAT="no"
        CAPTION="yes"    
        MAXIMIZEBUTTON="no"
        SHOWINTASKBAR="yes"
        SINGLEINSTANCE="yes"
        SYSMENU="yes"
        NAVIGABLE="yes"
        ICON="images/favicon.ico"
        WINDOWSTATE="normal">
    <STYLE> body {margin:0} </STYLE>
    </HEAD>
    <BODY onload="Set()" >
    <IFRAME src="blahblah.htm" application=yes width=1030 // width is that of your window
    height=95 marginwidth=0 marginheight=0   /// height is that of your window
    frameborder=0>Iframes not supported</IFRAME>
    </BODY>
    </HTML>
    

    Note that you don't have to use an iframe as he does, you can put your HTML right in the HTA file.

    评论

    报告相同问题?

    悬赏问题

    • ¥15 matlab处理脑电数据悬赏(时序图+预处理+频谱图)
    • ¥100 r语言多元回归模型怎么看表达式
    • ¥15 PMM 9010/30P
    • ¥15 pom文件依赖管理,未找到依赖
    • ¥15 现在后端返回给我一堆下载地址,都是一个视频切片后的,如何在uniapp安卓环境下将这些分片的视频下周并且合并成原始视频并下载到本地。
    • ¥15 Unity导出2D项目运行时图片变成马赛克
    • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
    • ¥15 matlab中此类型的变量不支持使用点进行索引
    • ¥15 咨询第六届工业互联网数据创新大赛原始数据
    • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!