Current location: Hot Scripts Forums » General Web Coding » JavaScript » Send info from a form to a php page


Send info from a form to a php page

Reply
  #1 (permalink)  
Old 11-06-06, 02:44 PM
magicadmin magicadmin is offline
Newbie Coder
 
Join Date: Jun 2006
Location: UK
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Send info from a form to a php page

Hi all,

I want to send some info from a form to a php page without reloading the page,
I have tried some AJAX but its not 100% right, it works some of the time but some times its crashing out my server, it make my CPU run at 100% so i think there is a big bug in it.

Code:
var xmlHttp

function clearwall()
{
var url="./includes/graffiti.php?painttext=&adminreset=1&userwallwiped=1"
xmlHttp=GetXmlHttpObject(wallstateChanged)
xmlHttp.open("POST", url , true)
xmlHttp.send(null)
} 

function wallstateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
wipegraffitiwall()
} 
} 

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
}
Dose any one know how to do this or whats up with my ajax??

Thanks all
__________________
Midnight Fun
Reply With Quote
  #2 (permalink)  
Old 11-07-06, 04:09 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
First, I don't see anything wrong with the code. I think the servercode might have a bug (or maybe a connection problem which stops the server from receiving the whole message). Have you tried printing out what the server gets each time the script calls it?

Second, don't detect the browser used, detect which objects are available. (Some browsers can be set to appear as others, even if they don't support the same things.)

One good way to do this is to try to create the ActiveX objects in the order you'd like them to be prioritized.
Here's one way to do it.
Code:
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null

	if(window.ActiveXObject){

		try{
			objXmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch(er){
			try{
				objXmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch(er2){
				alert("Error. Scripting for ActiveX might be disabled") 
			}			
		}
		if(objXmlHttp){
			objXmlHttp.onreadystatechange=handler 
		}
	}
	else{ 
		try{
			objXmlHttp=new XMLHttpRequest()
			objXmlHttp.onload=handler
			objXmlHttp.onerror=handler 
		}
		catch(er3){
			alert("Error. Failed to init XMLHttpRequest")
		}
	}
	return objXmlHttp
}
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old 11-07-06, 08:45 AM
magicadmin magicadmin is offline
Newbie Coder
 
Join Date: Jun 2006
Location: UK
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks once again TwoD for your help.

The problem i have is very confusing as its not all the time... the script works most of the time but evey so often it just messes up big time... i think you could be right it maybe the php side of things but i never have any errors in the log...
__________________
Midnight Fun
Reply With Quote
  #4 (permalink)  
Old 11-07-06, 02:50 PM
magicadmin magicadmin is offline
Newbie Coder
 
Join Date: Jun 2006
Location: UK
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
the problem was php but as of why it was not happening all the time i have not worked out yet...
__________________
Midnight Fun
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to php file, via a form? j-a-m-i-n PHP 4 10-14-06 04:43 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
checkCheckboxGroup broken after form consolidation ski_woman JavaScript 0 01-12-05 11:00 AM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 12:11 AM
E-Mail form / Send code on one page perleo PHP 4 02-11-04 01:16 AM


All times are GMT -5. The time now is 11:20 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.