我对我的 ajax 表格提交方式有异议。 我动态地提交一个表格, 在服务器一侧使用 php 处理它。 这是 ajax 成功功能 。
$.ajax({
type: "POST",
url: "register.php",
data: "uname="+uname+"&eid="+eid+"&pwd="+pass+"&cpwd="+cpass+"&country="+coun+"&contact="+contact,
dataType: "html",
success: function(data){
if(data!="error")
{
//alert(data);
$("#user_status", window.parent.document).html("Welcome "+data+" | <a href= forum/logout.php >Logout</a>");
if(window.parent.document.getElementById( post_user_name ))
$("#post_user_name", window.parent.document).html(msg);
parent.$.fancybox.close();
}
if(data=="error")
{
//alert(data);
$("#status").html("<span><center><font class= formright err_msg style= width:176px; >The user is already register with us.</font><center></span>");
return false;
}
Now if the user is valid he is logged in and f not there has to be an error like "Already exists".The valid part works fine but for invalid I return an error from the php file but still my error message doesn t show up and just error is printed on the screen.I am using fancybox for my forms(jquery fancybox) PHP code is
if($_POST[ pwd ]==$_POST[ cpwd ])
{
$username = $_POST[ uname ];
$email = $_POST[ eid ];
$password = md5($_POST[ pwd ]);
$cpassword = $_POST[ cpwd ];
$contact_no = $_POST[ contact ];
$country = $_POST[ country ];
$cnt = $checkUser[ cnt ];
if($cnt!=0)
{
echo "error";
//exit;
/*$_SESSION[ error_msg ] = Email Address already exists ;
redirect_to_link("index.html");*/
}
else
{
//echo "entered here";
$userArray = array();
//$user = return_post_value($_POST[ uname ]);
$userArray[ uname ] = return_post_value($_POST[ uname ]);
$userArray[ email ] = return_post_value($_POST[ eid ]);
$userArray[ password ] = md5(return_post_value($_POST[ pwd ]));
$userArray[ contact_no ] = return_post_value($_POST[ contact ]);
$userArray[ country ] = return_post_value($_POST[ country ]);
//print_r($userArray);
//exit;
$userObj->addUserValue($userArray);
$_SESSION[ username ]= $userArray[ uname ];
echo $userArray[ uname ];
// return $user;
}
The echo $userArray[ uname ]; part works but echo "error" doesn t.Checked in Firebug response header,i can see the error word returned.
Can anyone throw some light on it?
Thanks