SitePoint Sponsor |
|
User Tag List
Results 1 to 20 of 20
Thread: Multiple Ajax's
-
Feb 1, 2008, 12:30 #1
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Multiple Ajax's
Hi, say I have:
Code:<script type="text/javascript"> function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { var data = xmlHttp.responseText.split("\n"); document.Register.secimg.src=data[0]; document.Register.sessid.value=data[1]; } } xmlHttp.open("GET","scajax.php?r=" + Math.random(),true); xmlHttp.send(null); } </script>
Thanks
-
Feb 1, 2008, 12:56 #2
- Join Date
- May 2006
- Location
- Ventura, CA
- Posts
- 2,750
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
When you say using a different ajax function, do you mean the onreadystatechange function? If so you can just pass a function in as a parameter, then set xmlHttp.onreadystatechange equal to the function argument.
-
Feb 1, 2008, 13:11 #3
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, just did. Cheers.
-
Feb 1, 2008, 13:30 #4
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks. I have a different problem.
Is it possible to change the onmouseover data of <a> link?
Code:var udata = xmlHttp.responseText.split("\n"); document.Register.userimg.src=udata[0]; document.Register.useromo.onmouseover=udata[1];
-
Feb 1, 2008, 13:34 #5
- Join Date
- May 2006
- Location
- Ventura, CA
- Posts
- 2,750
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What is the value of udata[1]?
-
Feb 1, 2008, 13:37 #6
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry forgot to mention,
for testing I have
PHP Code:echo "images/regt.gif";
echo "\n";
echo "return overlib('Test.', STICKY, CAPTION, 'Test', CENTER);window.status='Tactical Mafia - Registration';return true;";
-
Feb 1, 2008, 13:42 #7
- Join Date
- May 2006
- Location
- Ventura, CA
- Posts
- 2,750
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Anything come up in a javascript console of some kind (Firefox's Error Console for example)?
-
Feb 1, 2008, 13:43 #8
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
document.Register.useromo has no properties in firebug. I've been out of JS for a while but I had this once and I can't remember how to fix it.
-
Feb 1, 2008, 13:57 #9
- Join Date
- May 2006
- Location
- Ventura, CA
- Posts
- 2,750
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That error means that document.Register.useromo is not a valid object:
Code:var udata = xmlHttp.responseText.split("\n"); document.Register.userimg.src=udata[0]; document.Register.useromo.onmouseover=udata[1];
-
Feb 1, 2008, 14:01 #10
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes, this is what I have:
PHP Code:<a name="useromo" onmouseover="return overlib('This will be your name (who you are known as) used throughout Tactical Mafia.', STICKY, CAPTION, 'Username', CENTER);window.status='Tactical Mafia - Registration';return true;" onmouseout="nd();window.status='Tactical Mafia';return true;" href="register1.php#" style=""><img src="images/regq.gif" name="userimg" border="0" alt="" /></a>
I can't figure it out.Last edited by TacMaf; Feb 1, 2008 at 15:55.
-
Feb 1, 2008, 17:18 #11
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can <a> tags even be changed? I tried changing a text input field and it worked fine?
-
Feb 1, 2008, 17:39 #12
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK I got rid of the <a> tags and now I'm just using the image. The .src changing works but the .onmouseover doesnt.
-
Feb 1, 2008, 17:50 #13
- Join Date
- Jul 2007
- Posts
- 345
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I don't think you can set the onmouseover property to a string in code. A string is used for HTML attributes but a function must be used in code.
Maybe something like:
Code:document.Register.useromo.onmouseover=new Function(udata[1]);
Code:document.getElementById("useromo").onmouseover = new Function(udata[1]);
-
Feb 1, 2008, 17:53 #14
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah I see. So what kind of thing would I need in the function?
Thanks very much.
-
Feb 1, 2008, 17:56 #15
- Join Date
- Jul 2007
- Posts
- 345
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does udata[1] not contain a function returned as a string from php code?
-
Feb 1, 2008, 18:01 #16
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
udata[1] is just "Test" set in the ajax script called using GET.
-
Feb 1, 2008, 18:09 #17
- Join Date
- Jul 2007
- Posts
- 345
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You have this JavaScript:
Code:var udata = xmlHttp.responseText.split("\n");
Code:echo "images/regt.gif"; echo "\n"; echo "return overlib('Test.', STICKY, CAPTION, 'Test', CENTER);window.status='Tactical Mafia - Registration';return true;";
-
Feb 3, 2008, 10:13 #18
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Right. I'm not sure if I've done this right but this is what I have:
Code:var udata = xmlHttp.responseText.split("\n"); document.Register.userimg.src=udata[0]; document.Register.userimg.onMouseOver=new Function(udata[1]);
.
Thanks.
-
Feb 3, 2008, 10:59 #19
- Join Date
- Jul 2007
- Posts
- 345
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
JavaScript is case sensitive.
Try onmouseover rather than onMouseOver
-
Feb 3, 2008, 11:07 #20
- Join Date
- Dec 2005
- Location
- Manchester, United Kingdom
- Posts
- 663
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It worked! Thank you r51!!
Bookmarks