Help Please

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
I have a simple Ajax Post script and there is a bug in it I cannot find. The simplest bugs are the hardest to solve. Please help me with my script and I will advertise your site in my newsletter or give 50 credits :)
HTML:
<?php
echo $_POST["do"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Post Tester</title>
<script type="text/javascript">
function Send() {
 var data = "do=" + document.post.name.value;
 alert(AjaxRequest("POST","Post.php",data,true));
 return false;
}

function AjaxRequest(method,url,data,action){
 if (method==null || url==null) {
  alert("Missing Parameters, request aborted."); return false;}
 if (method=="POST" && data==null) {
  alert("Missing data for post method, request aborted."); return false;}
 var xmlHttp = false;
 try {xmlHttp=new XMLHttpRequest(); 
  if (xmlHttp.overrideMimeType) xmlHttp.overrideMimeType('text/html');}
 catch (e){try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
 catch (e){try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
 catch (e){alert("Your browser does not support AJAX!");  return false;}}}

xmlHttp.onreadystatechange=function(){
 if(xmlHttp.readyState!=4) return;
 if(xmlHttp.status==200){
 return xmlHttp.responseText;}
 else {alert("Request Failed: " + xmlHttp.statusText)}
}

 xmlHttp.open(method,url,action);
 if (method=="POST") {
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", data.length);
  xmlHttp.setRequestHeader("Connection", "close");
 }
 xmlHttp.send(data);
}
</script>
</head>

<body>
<form name = "post" method="post" onsubmit="return Send();" action="javascript:alert('Failed.');">
<input type="text" name="name" /><input type="submit" value="Send" />
</form>
</body>
</html>
Warning: AjaxRequest() does not alway return a value, line 39. Thank you for your help.
 
Last edited:

Loneua Technologies

New Member
Messages
624
Reaction score
0
Points
0
Looks fine to me :)

I will pay you 50 Credits to advertise my site on your Newsletter.

PM Me with the number of people it is being sent to to confirm a number.
 

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Just went through your coding. couldn't find any error.

But i am posting here the my version of it here.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Post Tester</title>
<script type="text/javascript">
function Send() {
 var data = "do=" + document.post.name.value;
 AjaxRequest("POST","test.php",data,true);
 return false;
}
var xmlHttp = false;
function AjaxRequest(method,url,data,action){
 if (method==null || url==null) {
  alert("Missing Parameters, request aborted."); return false;}
 if (method=="POST" && data==null) {
  alert("Missing data for post method, request aborted."); return false;}
 
 try {xmlHttp=new XMLHttpRequest(); 
  if (xmlHttp.overrideMimeType) xmlHttp.overrideMimeType('text/html');}
 catch (e){try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
 catch (e){try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
 catch (e){alert("Your browser does not support AJAX!");  return false;}}}

xmlHttp.onreadystatechange= responsedata;
 xmlHttp.open(method,url,action);
 if (method=="POST") {
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", data.length);
  xmlHttp.setRequestHeader("Connection", "close");
 }
 xmlHttp.send(data);
}
function responsedata() 
{
if(xmlHttp.readyState!=4) return;
 if(xmlHttp.status==200){
 document.getElementById("result").innerHTML = xmlHttp.responseText;}
 else {alert("Request Failed: " + xmlHttp.statusText)}
}
</script>
</head>

<body>
<div id="result"></div>
<form name = "post" method="post" onsubmit="return Send();" action="javascript:alert('Failed.');">
<input type="text" name="name" /><input type="submit" value="Send" />
</form>
</body>
</html>

this goes in one page. and in another name it as test.php

the coding will be

Code:
<?php print $_POST['do']; ?>

this will do any thing more. pm me, I will post the code here.
 
Top