Jump to content
xisto Community
Sign in to follow this  
masugidsk8r

Scripting Help On Ajax Shoutbox

Recommended Posts

HI, I'm currently working on an AJAX web app. It's a shoutbox. I have here attached the .js file fully documented so it's easy to understand.

Problem: An error message alert occurs in IE 6
Help: I need someone who can fix a code so that the error won't show up in IE.

Note: I've tested it under Firefox and Opera and it works very well.

Here's the code:

/** * ezShout - AJAX/PHP ShoutBox * by Albert Villaroman *  * For help and tutorials on usage, please refer to manual *  * Note: Due to JS lack of standard OOP conventions, treat "Shoutbox Class" comment as a class constructor,  * and all states and methods encapsulated in it are properties of the class **///-----------------------------------------------------------------------------------// Shoutbox Class//-----------------------------------------------------------------------------------	/**	 * Pre: Sates	 */		var RecieverAj;			//AJAX object that makes requests to server for shouts	var SenderAj;			//AJAX object that sends shout out to server and store it in database	var refresh_sb;			//JS timer that will refresh list of shouts every 5 seconds	var lastShout_sb="";		//Global variable that stores last shout which is to be compared to continuosly refreshed list of shout outs - Purpose: to prevent repetitive refresh of the list		/**	 * I. Obtain latest shouts from database every x seconds	 */		//request the server for latest shouts	function loadShouts_sb() {		RecieverAj = new ajaxConn();		RecieverAj.serverscript = "ezShout/includes/procedures/fetchShouts.php";		RecieverAj.setValues("rand=" + Math.random());		RecieverAj.connect("displayShouts_sb", "GET");	}	window.onload = loadShouts_sb();		//display list of shouts when response from server is recieved	function displayShouts_sb (response) {		switch (response) {			case lastShout_sb: break;			default: alert("hi"); document.getElementById("shoutcontents_sb").innerHTML = response; lastShout_sb = response; setRefreshTime_sb(); break; 		}	}		//set a Timer that runs loadShouts_sb in 5 seconds	function setRefreshTime_sb() {		refresh_sb = setTimeout('refreshShouts_sb()', 5000);	}		//request again after 5 seconds	function refreshShouts_sb () {		RecieverAj.connect("displayShouts_sb", "GET");		clearTimeout(refresh_sb);		refresh_sb = setTimeout('refreshShouts_sb()',5000);	}					/**	 * II. Send a shout out to the server and store it in database 	 */		//onSubmit, send `name` and `message` input to server via `SenderAj`		function sendShout_sb () {		var name = document.getElementById("shouter_sb").value;		var message = document.getElementById("shout_sb").value;			SenderAj = new ajaxConn();		SenderAj.serverscript = "ezShout/includes/procedures/sendShout.php";		SenderAj.setValues("name=" + name + ",message=" + message + ",rand=" + Math.random());		SenderAj.connect("isShoutSuccessful_sb", "POST");	}		//check if shout out sent is stored in the database; successful	function isShoutSuccessful_sb (response) {		switch (response) {			case "true": alert("Your shout has been sent."); break;			case "false": alert("Unsuccessful post. Please report this."); break;		}				document.getElementById("shout_sb").value = "your message";		document.getElementById("shout_sb").style.background = "#E9E9E9";	}	//clear value of selected object	function clearValueOf_sb(object) {		object.value = "";		object.style.background = "#FFFFFF";	}//-----------------------------------------------------------------------------------// End of Shoutbox Class//-----------------------------------------------------------------------------------

You can view the application here: click here

Share this post


Link to post
Share on other sites

Well you get that same error message in IE 7 as well "unsuccessful post, report this" Of course my knowledge of ajax is limited but I would say the problem lies somewhere in here

/**	 * II. Send a shout out to the server and store it in database 	 */		//onSubmit, send `name` and `message` input to server via `SenderAj`		function sendShout_sb () {		var name = document.getElementById("shouter_sb").value;		var message = document.getElementById("shout_sb").value;			SenderAj = new ajaxConn();		SenderAj.serverscript = "ezShout/includes/procedures/sendShout.php";		SenderAj.setValues("name=" + name + ",message=" + message + ",rand=" + Math.random());		SenderAj.connect("isShoutSuccessful_sb", "POST");	}

in the post function and the connection to the database that is storing this shouts, take a look at your php file and see if you happen to forget to add a piece of code inthe php file that is failing to connect the db to the shoutbox.

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.