![]() |
hi guys need help with a simple ajax script please
i need the simplest way to add to my javascript code a way of getting data from a text file in the same directory as the index.html and putting the data into a variable called data1 to be used by the rest of the script
any ideas |
Yes, google for "simple Ajax example"
|
i cant seem to find an example that does what i need
|
i cant seem to believe that
This is what came up as the very first result googling for Ajax example Code:
var myvar = ""; |
ok thanx
i have played with this and i am finding it a problem...here is my code Code:
<script type="text/javascript"></script> could you please tell me what i am doing wrong |
Yes, you did not use my example above. Instead you removed the (important) callback onreadystatechange and treated the responseText from an asynchronous request (third parameter of open is true) as if it was a synchronous one ... which obviously doesn't work. Additionally, starting from IE7 you do not need a browser switch any more as every modern browser recognizes the XMLHttpRequest object.
|
i know i dont know as much as you but i am trying my best...
im more familiar with perl and c++.. could you please point out what i have done wrong and please help correct. i supply people with information on another forum for help with other languages. could you be a professional and help please |
http://bookofjavascript.com/Chapter16/Fig16-15.txt HTML that uses the following PHP
http://bookofjavascript.com/Chapter16/readTextFile.txt PHP file that opens and reads files |
Please try to adhere as close as possible to my first example ... and if it doesn't work, please come back with your rewritten code. Then we will find the problem.
The goal of this forum is not to write the code for you but to guide you to help yourself as good as possible. Code:
var myvar = ""; |
i dont get it im racking my brains for days now and still cant get this to work
here is what i have Code:
<script type="text/javascript"> |
This is a common mistake. Outside of onreadystatechange the "myvar" variable remains undefined, because this code will be executed BEFORE the request has finished.
Conclusion: Everything you want to do depending on the result of the request has to be (started from) inside the onreadystatechange callback Code:
var myvar = ""; |
| All times are GMT +1. The time now is 07:04 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.