-
I am having an Issue with refresh I think
Hi
Newby to ajax
I think I may be having the same problem as this post but I am not sure
http://www.dynamicdrive.com/forums/s...ad.php?t=27921
I created a form that uses the get method to get content from a webpage relative to the list of stock symbols that I have supplied in an array.
After a week on working on it I almost got it working the way I want it.
The only problem is that it does not display all the symbols and their realtive information all at once.
For example
I have three symbols in my array
when I open the form and click on the "Run Query" button
it retrieves the first symbol and it's relative infromation.
but when I click on the back button and press the "Run Query" button again I get two symbols from the list with the relative information and every time I repeat this step another one from the list is added.
I am not sure why it is doing this
is there a way around this.
Here's the code thanks
<html>
<head>
<title>Fetch Page</title>
<script language="JavaScript1.2">
var mysymbol = new Array();
mysymbol[0] = "A";
mysymbol[1] = "AAPL";
mysymbol[2] = "MSFT";
var req = new ActiveXObject("Microsoft.XMLHTTP");
function get_barchart_data(i,url) {
req.onreadystatechange = handleResponse;
req.open("GET", url, true);
req.send(null);
}
function handleResponse(i) {
var charactercount = req.responseText.length
var startstring = req.responseText.indexOf("Overall Average");
var newresponse = req.responseText.substring(startstring,charactercount)
var endstring = newresponse.indexOf("-")
var result = newresponse.substring(0,endstring)
if(req.readyState == 4)
if(req.status == 200)
document.write("Symbol: " + mysymbol[i] + " Barchart Overall Average: " + result.substring(endstring-4,endstring) + "<p>")
else
document.write("Error: " + req.status + " " + req.statusText);
}
function getdata(){
for (i=0;i<mysymbol.length;i++)
{
var url = "http://quote.barchart.com/texpert.asp?sym=" + mysymbol[i]
get_barchart_data(i,url)
handleResponse(i)
}
}
</script>
</head>
<body>
<FORM method="GET" name="ajaxGet" action="">
<INPUT type="BUTTON" value="Run Query" ONCLICK="getdata()">
</FORM>
</body>
</html>
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks