![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
PHP God
|
Ok just a quick question.. after sitting here for about half an hour trying to work out what's wrong with this script i come here in seek of guidence.
<script type="text/javascript">
function initialize(){
var xmlHttp;
try{
xmlHttp = new XMLHttpRequest();
}catch (e){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("No ajax!");
return false;
}
}
}
}
function mail(){
initialize();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState == 4)
{
document.getElementById("show_box").innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("GET","http://www.staticfire.co.uk/ajaxrequest.php?cmd=mail",true);
xmlHttp.send(null);
}
</script>The problem seems to be that it isn't recognising the initialize() function. But if i replace where i call the function with the code for that function it all runs fine. Am i missing something obvious here? -Thanks, Firefly |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Re: Problem with calling a function
Try replacing the call to initialize() with
window.onload = initialize;. |
|
|
|
|
|
#3 |
|
PHP God
|
Re: Problem with calling a function
Thanks for the reply but that didn't seem to make a difference. I can fix the problem by just putting the code for that function in each time i wish to use it but that seems very inconvinient
![]() |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Problem with calling a function
Try moving
var xmlHttp; outside the scope of the function. Make it the first line of the code, and not within the function call. I think that's because mail() refers to xmlHttp, but xmlHttp expires once initialize() ends. |
|
|
|
|
|
#5 |
|
PHP God
|
Re: Problem with calling a function
you know what.. that just worked! Thanks for the help my site now has a pm system with no page reloads
![]() |
|
|
|
|
|
#6 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Re: Problem with calling a function
Sane is correct...O great PHP god
I'd suggest the Firebug extension for Firefox (includes javascript debugging, a javascript command line, and can show ajax requests real time, among other things). This would have told you that initialize() was actually getting called. It would also be much less painful to use a library such as prototype or jQuery jQuery equivalent looks something like this. Warning: Untested. javascript Syntax (Toggle Plain Text)
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 Last edited by Dameon; Dec 1st, 2007 at 8:15 PM. |
|
|
|
|
|
#7 | |
|
PHP God
|
Re: Problem with calling a function
Quote:
Perhaps i should look at getting this Firebug extension you speak of as it sounds like it could be useful. |
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Problem with calling a function
Yep. I use that (although I didn't have to in this case). Mine's called the Web Developer extention, very handy. But Dameon could be referring to something similar.
|
|
|
|
|
|
#9 |
|
PHP God
|
Re: Problem with calling a function
Hi again sorry to bump this thread back up but i thought this was working fine till a friend told me he was getting errors from it. I tested the system on a few browsers and it was fine on IE7, Opera and Safari but on Firefox and Netscape it just comes up with "Length required". Can anyone tell me why this might happen? Thanks
__________________
mysql_query("DELETE chavs FROM earth") or die("chavs"); |
|
|
|
|
|
#10 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 816
Rep Power: 4
![]() |
Re: Problem with calling a function
You should mention the actual URL so we could look at it not working, or if it is a private page, post your current code. Also, the line number of the error would be a help.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calling an undeclared or undefined function in C/C++ | climbnorth | C | 2 | Oct 8th, 2006 12:02 AM |
| problem with a function | brad sue | Other Programming Languages | 3 | Apr 23rd, 2006 10:24 PM |
| problem with standard function | sparda | C | 8 | Oct 26th, 2005 2:27 PM |
| Problem passing multi-dimensional array to function | aznluvsmc | C | 2 | Aug 30th, 2005 10:00 PM |
| Problem when returning a string from a function in VC++ | vjkancha | C++ | 10 | Mar 7th, 2005 1:18 PM |