Jump to content

TypeError for setRequestHeader


deadpickle

Recommended Posts

I'm pretty new to javascript/ajax/php/html so bear with me.I am Trying to use ajax to connect to a database. The reason I am using ajax is so I can dynamically update the webpage as information is gathered about the database. So far I have is setup so that when a button is clicked:

<input type="button" value="Login" onclick="sqllogincheck(this.form)">

a function is ran that will connect up to the database server side:

<html><head><title>High Plains Regional Climate Center</title><link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"><?php wp_head(); ?></head><!--All functions for pages--><script>//login and get mysql tables, update table status viewfunction sqllogincheck(frm) {var xmlhttp; //All fields must be fullif (frm.sqlusr.value == "" || frm.sqlhost.value == "" || frm.sqlpwd.value == "") {  alert("Missing Fields!");}//use AJAX to setup a query to the serverelse {  xmlhttp=new XMLHttpRequest();  xmlhttp.onreadystatechange=function() {   if (xmlhttp.readyState==4 && xmlhttp.status==200) {	document.getElementById("dbstatus").innerHTML=xmlhttp.responseText;   }  }  //send POST request to server  xmlhttp=open("POST","citools/login.php",true);  xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");  xmlhttp.send("sqlusr=" + frm.sqlusr.value + "&sqlhost=" + frm.sqlhost.value + "&sqlpwd=" + frm.sqlpwd.value);  //alert("Username: " + frm.sqlusr.value + "\nHost: " + frm.sqlhost.value + "\nPassword: " + frm.sqlpwd.value)}}</script><body><div id="wrapper">  <div id="header">   <img src="<?php bloginfo('template_directory'); ?>/images/headers/top_logo.jpg" alt="HPRCC">   <!--<div id="menu">	<?php wp_nav_menu( array( 'theme_location' => 'header-menu', 'container_class' => '') ); ?>   </div>-->   <?php shailan_dropdown_menu(); ?>   <h1 id="pagetitle"><?php wp_title(); ?></h1>  </div>

When I test this code out I get the error "Uncaught TypeError: Object [object Window] has no method 'setRequestHeader'". I have the vague idea that this means there is no 'setRequestHeader' method in the xmlhttp object, but im not sure how to correct it.Just a bit more info here. I'm testing this page using localhost and am not sure if that has anything to do with the error. Also, I'm using Wordpress for my CMS and this is why I only posted the header here.Thanks for the help.

Link to comment
Share on other sites

You have an equal sign instead of a dot on this line: xmlhttp=open("POST","citools/login.php",true); That means you're calling window.open and setting xmlhttp to be a window object, and windows don't have ajax methods defined on them.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...