473,408 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

AJAX POST REQUEST--err

Hello Everyone,
With that alert statment alert("calling validateme for "+document.form1.elements[iCounter]); in js things would work fine but if i remoe the form is simply getting submitted in firebug i can see some error popping up like uncaught exception ...just care to look in code nad let me know if u found something

PHP file to handle resquest
<?php
/*This is a dummy code to handle the request*/
$method=$_POST["req"];
if($method=='POST')
{

$required = $_POST["sRequired"];
$typecheck = $_POST["sTypeCheck"];
$val = $_POST["val"];
}else
{
$required = $_GET["sRequired"];
$typecheck = $_GET["sTypeCheck"];
$val = $_GET["val"];
}
$res='';
if($typecheck=='email' && !empty($val))
{
$resq=validateEmail($val);
}

if(empty($val) && $required=='required')
{
$res='Required Fields';
}
else
{
if(empty($res))
$res=$resq;
else
$res='OK';

}
echo trim($res);
function validateEmail($val)
{
if (ereg ("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $val))
{
$em='OK';
}
else
{
$em="Invalid Email Address";
}
return $em;
}
?>



index.html

<!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" xml:lang="en" lang="en">

<head>
<title>Ajax Form</title>

<script type="text/javascript" src="validate.js"></script>

</head>

<body>
<fieldset>
<legend>Ajax Form</legend>


<form name="form1" id="form1" method="post" action="formvalidation.php" onSubmit="javascript: return attachFormHandlers();">
<table width="500">
<tr><td><div id="gShow"></div></td></tr>
<tr>
<td width="130">Username </td>
<td width="170"><input type="text" name="user" tabindex="1" id="user" class="validate required none usermsg"/></td>
<td id ="usermsg" class="rules"></td>
</tr>

<tr>
<td>Email </td>
<td><input type="text" name="email" tabindex="2" id="email" class="validate required email emailmsg" /></td>
<td id="emailmsg" class="rules"></td>
</tr>

<tr>
<td><input type="submit" name="Submit" value="Submit" tabindex="5" /></td>
</tr>

</table>

</form>
</fieldset>
</body>


</html>


javascript
//window.onload = attachFormHandlers;

var gShow; //error handling
var sUrl = "formvalidation.php?validationtype=ajax&val=";
var gErrors = 0;
var http
http = getHTTPObject();


function attachFormHandlers()
{
//alert("in attach");
var form = document.getElementById('form1');

if (document.getElementsByTagName)
{
var objInput = document.getElementsByTagName('input');
for (var iCounter=0; iCounter<form.length; iCounter++)
{
if(document.form1.elements[iCounter].type=='text')
{
alert("calling validateme for "+document.form1.elements[iCounter]);
validateMe(document.form1.elements[iCounter]);
}
}
}

if(gErrors<=0)
{
document.form1.submit();
return false;
}
else
{
alert("Fill all Required fields");
return false;
}

}


/*validateMe is the function called with onblur each time the user leaves the input box
passed into it is the value entered, the rules (which you could create your own), and the id of the area the results will show in*/
function validateMe(objInput) {
var str;
sVal = objInput.value;
//alert(sVal);
sRules = objInput.className.split(' ');
sRequired = encodeURI(sRules[1]);
sTypeCheck = encodeURI(sRules[2]); //typecheck are additional validation rules (ie. email, phone, date)
gShow = sRules[3];

/*Post*/
str=sUrl + sVal + "&sRequired=" + (sRequired) + "&sTypeCheck=" + sTypeCheck + "&req=POST";
http.open("POST","formvalidation.php",true);
http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
http.setRequestHeader("Content-length",str.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange=handleHttpResponse;
http.send(str);
/*GET
http.open("GET", sUrl + (sVal) + "&sRequired=" + (sRequired) + "&sTypeCheck=" + sTypeCheck, true);
http.onreadystatechange = handleHttpResponse; // handle what to do with the feedback
http.send(null); */

}


function handleHttpResponse() {
if (http.readyState == 4)
{
if(http.status == 200)
{
sResults = http.responseText.split(","); //results is now whatever the feedback from
if(sResults[0] != 'OK')
{
gErrors = gErrors + 1;
document.getElementById(gShow).innerHTML=http.resp onseText;
return false;
}
}
else if (http.status == 404)
{
alert ("Requested URL is not found.");
return false;
}
else if (http.status == 403)
{
alert("Access denied.");
return false;
}
else
{
document.getElementById(gShow).innerHTML="status is : "+http.status;
return false;
}
}
return false;

}


function getHTTPObject() {
var xmlhttp=null;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}


please look in these file and let me known if u found me wrong on smallest or sillest things

Would be a great help
Regards,
Mar 22 '07 #1
1 1960
ronverdonk
4,258 Expert 4TB
We can only (try to) help when you follow the Posting Guidelines for this forum! And one is to enclose all code within php or code tags when you show it. Without that, your code just looks like a bunch of unstructured lines.

Another thing is that we do not solve puzzles. Again: read the Posting Guidelines about problem handling.

We help people who have problems with their code. In order to do that you must show what the problem is, the error message or alike, what you have done to find the error and what to pinpoint the source of the problem.

Ronald :cool:
Mar 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I...
0
by: ramsden.paul | last post by:
This problem is driving me nuts! I have data which I am posting to my web service as follows: <code> new Ajax.Request("bookmarkws.asmx/putBookmarks", {method: "post", contentType: ...
6
by: mosesdinakaran | last post by:
Hi Everybody, As all knows the difference between GET and POST is in the way how the data is transfered, But in case of ajax Though it may be a post Request we need to format a querystring...
3
by: radix | last post by:
Hello, I have a aspx page with ajax scriptmanger update panel etc. I also have public string variables on the aspx page. Whenever postback happens from Ajax update panel, at server side all...
11
by: paitoon | last post by:
Hi, I have problem about ajax GET method. I use ajax to send mail and i use method GET. when i send alittle bit data it's work good but once i type so much in the form and send...i don't get...
3
sunbin
by: sunbin | last post by:
Hi, I am having in a Trouble when working with dynamic checkboxes (i.e. checkboxes with the same name, e.g. <input type="checkbox" name = "check" value="dynamic integer value">) I have...
1
by: simonbelmont | last post by:
Hi, The using the GET command with ajax works fine. Using POST only works if the data being retrieved is less than ~2400 bytes, otherwise it will be stuck in readyState = 3 and hang there. ...
2
by: amskape | last post by:
I created a script where a user can select from a variety of shipping options for an order from within a jQuery dialog box. The shipping rates are delivered via UPS & FedEx. Oddly enough, the ...
1
by: Qaisar Hayat | last post by:
I have a home page from where I call another page insertfrm.php through Ajax. The problem is that insertfrm.php works fine when loaded directly in browser but does not work when loaded through ajax...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.