加载使用JQuery或者Ajax的.txt文件 [英] Load .txt file using JQuery or Ajax

查看:96
本文介绍了加载使用JQuery或者Ajax的.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何解决下面,这样它将每次脚本!有时工作,有时没有。 临JQuery的的解释是什么原因导致这一点,但它并没有谈到如何解决它。我几乎可以肯定它是与阿贾克斯准备状态,但我不知道怎么写。该网站显示约99个不同的方式来编写AJAX和JQuery的,它有点势不可挡。

我的目标是创建一个HTML外壳,可填充与基于服务器的文本文件中的文本。例如:假设有一个名为AG及其内容的服务器上的一个文本文件是PF:PF-01,PF-02,PF-03等。我想拉这些信息和填充HTML DOM是以前用户看到的。 !一个是@#$#*&放大器;黄金与PHP,然后发现我的主人已经fopen()函数关闭。所以我在这里。

感谢您的帮助。

JS - plantSeed.js

  VAR pageExecute = {

fileContents:空,
页面preFIX:空,
幻灯片:空,

初始化:函数(){
    $阿贾克斯({
      网址:./seeds/Ag.txt
      成功:功能(数据){
            pageExecute.fileContents =数据;
      }
});
}
};
 

HTML - HEAD

 <脚本类型=文/ JavaScript的>
    pageExecute.init();
< / SCRIPT>
 

HTML - BODY

 <脚本类型=文/ JavaScript的>警报(pageExecute.fileContents); < / SCRIPT>
 

解决方案

试试这个:

  VAR pageExecute = {

    fileContents:空,
    页面preFIX:空,
    幻灯片:空,

    初始化:函数(){
        $阿贾克斯({
            网址:./seeds/Ag.txt
            异步:假的,
            成功:功能(数据){
                pageExecute.fileContents =数据;
            }
        });
    }
};
 

How can I fix the script below so that it will work EVERY TIME! Sometimes it works and sometimes it doesn't. Pro JQuery explains what causes this, but it doesn't talk about how to fix it. I am almost positive it has to do with the ajax ready state but I have no clue how to write it. The web shows about 99 different ways to write ajax and JQuery, its a bit overwhelming.

My goal is to create an HTML shell that can be filled with text from server based text files. For example: Let's say there is a text file on the server named AG and its contents is PF: PF-01, PF-02, PF-03, etc.. I want to pull this information and populate the HTML DOM before it is seen by the user. A was @#!#$*& golden with PHP, then found out my host has fopen() shut off. So here I am.

Thanks for you help.

JS - plantSeed.js

var pageExecute = {

fileContents:"Null",
pagePrefix:"Null",
slides:"Null",

init:function () {
    $.ajax({
      url: "./seeds/Ag.txt",
      success: function (data){
            pageExecute.fileContents = data;
      }
});
}
};

HTML - HEAD

<script type="text/javascript">
    pageExecute.init();
</script>

HTML - BODY

<script type="text/javascript"> alert(pageExecute.fileContents); </script>

解决方案

Try this:

var pageExecute = {

    fileContents:"Null",
    pagePrefix:"Null",
    slides:"Null",

    init: function () {
        $.ajax({
            url: "./seeds/Ag.txt",
            async: false,
            success: function (data){
                pageExecute.fileContents = data;
            }
        });
    }
};

这篇关于加载使用JQuery或者Ajax的.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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