0

みんな私はここに状況があります。ユーザーからの入力を検証しようとしています。入力が if の場合は!= ""if の内部で実行され、それ以外の場合は else の内部で実行されます。検証は、1 つのことを除いて非常に機能しています。条件は false ですが、まだ if 条件内にあり、このコードを使用してシステム全体を更新しています$(location).attr('href','account_setting_registrar.php');

手伝って頂けますか?

        $(document).ready(function (){
         var username ;
         var eadd;

$('#change_usrname_button').click(function (){
    username = $('#new_chnge_username').val();      

            if(username != "" ){
                    $.ajax({
                        type: 'POST',
                        url: 'account_setting_registrar_get.php',
                        dataType: 'json',
                        data:'username='+username,
                        success: function (data){


                                   if(data.error == false){

                                    alert("your username is successfuly changed");

                                       $(location).attr('href','account_setting_registrar.php');
                                   }
                                   else{
                                    alert("update error");
                                 }
                       }  
                    });

                }

                else{
                   alert("please put the new username");
                 }


});



            $('#change_eadd_button').click(function (){


                eadd = $('#new_chnge_eadd').val();


                if(eadd != "" ){
                        $.ajax({
                            type: 'POST',
                            url: 'account_setting_registrar_get.php',
                            dataType: 'json',
                            data:'emailadd='+eadd,
                            success: function (data){

                               if(data.error == false){

                                alert("your email address is successfuly changed");
                                $(location).attr('href','account_setting_registrar.php');
                               }

                               else{
                                alert("update error");
                               }

                             }
                        });
                 }

                 else{
                   alert("please put the new username");
                 }



        });

            });
4

3 に答える 3

1

あなたの検証はもう少し徹底すべきだと思います...

null空の文字列のみをチェックしていますが、ユーザー名がまたはundefined同様に有効である必要はありません。

検証は次のようにする必要があります。

if (username) {
 // ajax
}

これにより、以下がチェックされます。

  • ヌル
  • 未定義
  • NaN
  • 空文字列 ("")
  • 0
  • 間違い
于 2012-09-28T04:30:53.160 に答える
0

data.error=='false'取得する可能性のある応答は json 形式の文字列であるため、使用する必要があります。

于 2012-09-28T05:25:10.133 に答える
-1
       $(document).ready(function (){
         var username ;
         var eadd;

$('#change_usrname_button').click(function (){
    username = $('#new_chnge_username').val();      

            if(username){
                    $.ajax({
                        type: 'POST',
                        url: 'account_setting_registrar_get.php',
                        dataType: 'json',
                        data:'username='+username,
                        success: function (data){


                                   if(data.error == true){

                                    alert("your username is successfuly changed");

                                       $(location).attr('href','account_setting_registrar.php');
                                   }
                                   else{
                                    alert("update error");
                                 }
                       }  
                    });

                }

                else{
                   alert("please put the new username");
                 }


});



            $('#change_eadd_button').click(function (){


                eadd = $('#new_chnge_eadd').val();


                if(eadd){
                        $.ajax({
                            type: 'POST',
                            url: 'account_setting_registrar_get.php',
                            dataType: 'json',
                            data:'emailadd='+eadd,
                            success: function (data){

                               if(data.error == true){

                                alert("your email address is successfuly changed");
                                $(location).attr('href','account_setting_registrar.php');
                               }

                               else{
                                alert("update error");
                               }

                             }
                        });
                 }

                 else{
                   alert("please put the new username");
                 }



        });

            });

これを試してみてください。

于 2012-09-28T04:35:54.853 に答える