TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-15-2008, 12:01 PM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default xmlHttp.open is not a function

I keep getting this error for no reason at all.

Heres the code
Code:
	  var xmlHttp = new XMLHttpRequest;
          xmlHttp.open("POST","*******************/?id=" + id + "&n=" + n, true);
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-15-2008, 12:18 PM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

try:
Code:
var xmlHttp = new XMLHttpRequest();
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 02-15-2008, 02:27 PM   #3 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Here's a little insight into the inner workings of XMLHttpRequest();
Ajax (XMLHTTPRequest) Tutorial and Demo
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 02-15-2008, 04:17 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

i think the problem was he missed out the '( )', so therefore javascript wouldnt have seen the XMLHttpRequest class (in javascripts case, a function) and was looking for a var called XMLHttpRequest, it created the object but it didnt have the 'open()' method defined (once again function in the world of OO JS).

Im no expert in javascript but thats what i think he did wrong.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 02-15-2008, 07:16 PM   #5 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Orc> Are you testing this with IE? IE doesn't have an XMLHttpRequest object.

I personally prefer the Wikipedia article, it's essentially the API for working with XHR.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 02-15-2008, 11:26 PM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Firefox, by the way, I tried it with the two parentheses before I took them out, it's the same error.


By the way, I've already seen tons of tutorials, I also have xmlHttp.open in a function, maybe that helps? Those are arguments inside it from the function.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-15-2008, 11:34 PM   #7 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Heres the error from Firebug,
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-15-2008, 11:40 PM   #8 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

What happened to the layout? But umm,
Code:
 function ******* (n,id)
 {
 xmlHttp.open("POST","*****************/?id=" + id + "&n=" + n, true);
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-15-2008, 11:51 PM   #9 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

The firebug also said it has something to do with an OnClick. The only OnClick is this:
Code:
onClick="********(1, '.$row['id'].')"
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-15-2008, 11:53 PM   #10 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You're not really giving us enough information to go on. Random snippets of code (which change continually) showing us the line that is 'broken' is a start but from what you've shown us there shouldn't be a problem.

Write "xmlHttp" (and press Enter) in the Firebug command line and see what it tells you.
Salathe is offline  
Reply With Quote
Old 02-15-2008, 11:59 PM   #11 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
You're not really giving us enough information to go on. Random snippets of code (which change continually) showing us the line that is 'broken' is a start but from what you've shown us there shouldn't be a problem.

Write "xmlHttp" (and press Enter) in the Firebug command line and see what it tells you.
Nothing.. It's just blue text listing. ;/
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-16-2008, 12:03 AM   #12 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Fine heres some of the code:
Code:
echo '<script type="text/javascript">
	  
	  var xmlHttp = new XMLHttpRequest();
	  
	  try {
	  // Intranet Explorer
	  xmlHttp = new ActiveXObject("Msxml.xmlHttp");
	  
	  } catch (e)
	  {
	  xmlHttp = false;
	  }
	  
	  try {
	   xmlHttp = new ActiveXObject("Micrsoft.xmlHttp");
	  } catch (e)
	  {
	  	xmlHttp = false;
	  }
	  
	  
	  function userAmount (id,amount)
	  {
	   xmlHttp.open("GET","***********/screenshots/?id=" + id + "&ua=" + amount, true);
	   xmlHttp.send(null);
	   
	  }
	  
	  function stateEffect()
	  {
	     if (xmlHttp.readyState != 4) 
   {
    starReturn.innerHTML = "<img src=\'http://***********/img/loading.gif\' alt=\'loading..\' title=\'Loading..\'> ";
    
    return false;
   } else if (xmlHttp.readyState == 4)
   {
   
     starReturn.value = "Successfully rated!";
     
    } else {
     starReturn.value =  xmlHttp.responseText; 
    }
    }
	  
 function StarRate (n,id,pre)
 {
 xmlHttp.open("POST","/?id=" + id + "&n=" + n + "&pre=" + pre, true);
  xmlHttp.send(null);
  
 starReturn = document.getElementById(\'starReturn\');
  
  xmlHttp.onreadystatechange = stateEffect();
  {    
   }
  }
</style>';
Yes I am trying to make a rating system with AJAX. So far the AJAX fails.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-16-2008, 12:13 AM   #13 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Code:
 xmlHttp.open("POST","/?id=" + id + "&n=" + n + "&pre=" + pre, true);
It's just this one line is killing it all.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-16-2008, 12:21 AM   #14 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The problem is in the way that you're creating the xmlHttp object. First you create an instance of XMLHttpRequest, then you try and use ActiveX which overwrites the already created object. That means, if the ActiveX object isn't available the xmlHttp object is rendered useless (as you know). You'll need to re-order/structure where you assign the new instance of whatever to xmlHttp such that you only try to use the IE approaches if 'new XMLHttpRequest' failed.
Salathe is offline  
Reply With Quote
Old 02-16-2008, 12:27 AM   #15 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Okay, thank you.. But now I get this:
Code:
uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: ********************************* :: StarRate :: line 429" data: no]

// The line:
xmlHttp.send(null);
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:09 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design