Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  15] [ 3]  / answers: 1 / hits: 106565  / 12 Years ago, sat, july 21, 2012, 12:00:00

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>

More From » ajax

 Answers
339

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

[#84114] Thursday, July 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zane

Total Points: 471
Total Questions: 94
Total Answers: 91

Location: Bahrain
Member since Sun, Mar 27, 2022
2 Years ago
;