English 中文(简体)
Ajax格式化申请
原标题:Ajax form request

我对我的 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+"&nbsp;&nbsp;|&nbsp;&nbsp;<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

最佳回答

使用此选项比较是否( $. trim( data)! = "error" )

并且不重新检查是否($.trim(数据)=“error”)

使用

if($.trim(data)!="error")
{
 //
}
else{
//
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签