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
Warning: AjaxRequest() does not alway return a value, line 39. Thank you for your help.
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>
Last edited: