TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   xmlHttp.open is not a function (http://www.talkphp.com/javascript-ajax-e4x/2251-xmlhttp-open-not-function.html)

Orc 02-15-2008 12:01 PM

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);


sketchMedia 02-15-2008 12:18 PM

try:
Code:

var xmlHttp = new XMLHttpRequest();

ReSpawN 02-15-2008 02:27 PM

Here's a little insight into the inner workings of XMLHttpRequest();
Ajax (XMLHTTPRequest) Tutorial and Demo

sketchMedia 02-15-2008 04:17 PM

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.

SOCK 02-15-2008 07:16 PM

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.

Orc 02-15-2008 11:26 PM

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.

Orc 02-15-2008 11:34 PM

Heres the error from Firebug,

Orc 02-15-2008 11:40 PM

What happened to the layout? But umm,
Code:

function ******* (n,id)
 {
 xmlHttp.open("POST","*****************/?id=" + id + "&n=" + n, true);


Orc 02-15-2008 11:51 PM

The firebug also said it has something to do with an OnClick. The only OnClick is this:
Code:

onClick="********(1, '.$row['id'].')"

Salathe 02-15-2008 11:53 PM

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.

Orc 02-15-2008 11:59 PM

Quote:

Originally Posted by Salathe (Post 10844)
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. ;/

Orc 02-16-2008 12:03 AM

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.

Orc 02-16-2008 12:13 AM

Code:

xmlHttp.open("POST","/?id=" + id + "&n=" + n + "&pre=" + pre, true);
It's just this one line is killing it all.

Salathe 02-16-2008 12:21 AM

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.

Orc 02-16-2008 12:27 AM

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);



All times are GMT. The time now is 02:33 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0