Trouble with 'open()' in AJAX

This is a discussion on "Trouble with 'open()' in AJAX" within the JavaScript Forum section. This forum, and the thread "Trouble with 'open()' in AJAX are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 8th, 2007, 20:59
New Member
Join Date: Aug 2007
Location: Coventry
Age: 14
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Trouble with 'open()' in AJAX

Can anyone see whats the problem with this code?
HTML: Select all
<script type="text/javascript">
var xmlHttp;
function stateChanged() { 
 if (xmlHttp.readyState==4) { 
  document.getElementById("mysql_check").innerHTML=xmlHttp.responseText;
 }
}
function getXmlHttpObject() {
 var xmlHttp = null;
 if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } else if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  }
 return xmlHttp;
}
function mysqlReset() {
 document.getElementById("mysql_check").innerHTML = "<input type=\"button\" value=\"Check Connection\" onClick=\"mysqlCheck()\">"
}
function mysqlCheck() {
 document.getElementById("mysql_check").innerHTML = "Checking...";
 var host = document.getElementById("mysql_host").value;
 var user = document.getElementById("mysql_user").value;
 var pass = document.getElementById("mysql_pass").value;
 var db = document.getElementById("mysql_db").value;
 if (host.length==0 || user.length==0 || pass.length==0 || db.length==0) {
  alert("Please fill in all fields");
  mysqlReset();
  return;
 }
 xmlHttp = getXmlHttpObject;
 if (xmlHttp==null) {
  alert("Your browser doesn't suppert AJAX which is needed to check your connection");
  mysqlReset();
  return;
 }
 var url = "http://www.stuff4web.co.uk/SCMS/admin_check_mysql.php?h="+host+"&u="+user+"&p="+pass+"&d="+db+"&s="+Math.random()*10;
 xmlHttp.onreadystatechange = stateChanged;
 xmlHttp.open("GET",url,true);          // LINE 74
 xmlHttp.send(null);
}
</script>
I am getting the error "Object doesn't support this property or method" on line 74 (marked above)
Reply With Quote

  #2 (permalink)  
Old Aug 9th, 2007, 09:24
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trouble with 'open()' in AJAX

Hello

On line 41 you have a return statement outside a function. Return is used to return something from a function.

Why not put your what to do if no support for AJAX into the getXmlHttpObject function?

Hope that helps
Reply With Quote
  #3 (permalink)  
Old Aug 9th, 2007, 09:48
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: Trouble with 'open()' in AJAX

I think I have the problem. This should work anyway.

You have :

Code: Select all
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true);          // LINE 74
While it should be:

Code: Select all
xmlHttp.open("GET",url,true);          // LINE 73
xmlHttp.onreadystatechange = stateChanged;
You have to open the request before you can tell it what to do with a response.

Blake
Reply With Quote
Reply

Tags
ajax, open, trouble, xmlhttp

Thread Tools

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open-Source Ajax/PHP (or Python) Webmail calande Job Opportunities 0 Feb 3rd, 2008 02:03
Open Thource - For Open Source Thoughts Rakuli Free Web Site Critique 44 Oct 9th, 2007 09:51
Ajax Messages (Ajax Demonstration) iMarc JavaScript Forum 1 Mar 21st, 2007 22:48
try to open php and asks if i want to open or save file steven rowlands PHP Forum 6 Feb 20th, 2007 21:42
Beta Test new Open Source AJAX HTML/CSS Software arrowplain Web Page Design 0 Feb 27th, 2006 22:19


All times are GMT. The time now is 22:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43