SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Help with Ajax..
-
Jun 10, 2007, 10:41 #1
- Join Date
- Jun 2007
- Location
- Regina, SK, Canada
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with Ajax..
Hi all! Could anyone tell me why this wont work...
The function works when i remove the (ver) after "stateChanged" (inside showCat function). What I'm doing is I want to use this function more than once, so Im combining PHP to throw in a variable in showcat(str,ver). The ver is where the integer goes and auto-increments using a for loop that is being called through PHP
This is my PHP... (which works fine)..
<select name="blah" onchange="showCat(ver,$i)">
<option>blah</option>
</select>
... however the ajax wont work!
Please help!
<script type="text/javascript">
var xmlHttp
function showCat(str,ver)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getcat.php"
url=url+"?id="+str
xmlHttp.onreadystatechange=stateChanged(ver)
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(ber)
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint"+ber).innerHTML=x mlHttp.responseText
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
</script>
-
Jun 10, 2007, 11:40 #2
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Welcome to SitePoint Forums, jboesch.
To answer your question, I suggest you read this.We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
-
Jun 10, 2007, 11:43 #3
- Join Date
- Jun 2007
- Location
- Regina, SK, Canada
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, but it didn't really help me
I want to use this function again and again and display the text in a diff element each time.. eg. txtHint1, txtHint2, txtHint3.. thats why im adding +ber to getElementByID("txtHint"+ber);
-
Jun 10, 2007, 12:03 #4
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That explained that this:
Code:xmlHttp.onreadystatechange=stateChanged(ver)
Code:xmlHttp.onreadystatechange=function(){stateChanged(ver)}
I am concerned that your code may not be following JavaScript Best Practices. I recommend you read up on them.We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
-
Jun 10, 2007, 12:08 #5
- Join Date
- Jun 2007
- Location
- Regina, SK, Canada
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I didn't post all of my PHP, but it works fine. The AJAX was my difficulty, I'm pretty new to it. I grabbed this code from a tutorial, but with that added suggestion you made, it all works!
Thank you very much!
Bookmarks