0
**FORM**
<form onSubmit="check_cat_to_save();return false;">
.....
</form>

上面的 DIV 需要在版本上更新,但不知道为什么它不起作用

AJAX 函数

 function check_cat_to_save(){
    $.ajax({
        type:'POST',
        url:'edit_cat.php',
        data:"cat_name="+$('#cat_name').val()+"&cat_id="+$('#cat_id').val()+"&cat_desc="+$('#cat_desc').val()+"&cat_publish="+$('#cat_publish').val(),
        success:function(response){
            if(response=='6'){$('#error').css({'color':'red','display':'block'}).html('Category already exists!')}
            else if(response=='7'){$('#error').css({'color':'#0c0','display':'block'}).html('Sucessfully edited category!')}
            else if(response=='8'){$('#error').css({'color':'red','display':'block'}).html('OOPS Something went wrong!')} 
            else if(response=='9'){$('#error').css({'color':'red','display':'block'}).html('Please Fill all the feilds!')} 
            else {$('#error').css({'color':'red','display':'block'}).html('Please Fill all the feilds!')}
            }
        });
    };

在上述部分中,响应部分不起作用,即错误类 DIV 在编辑时不显示任何响应

编辑猫.php

<?php
    $cat_id = mysql_real_escape_string($_POST["cat_id"] );
    $cat_name = mysql_real_escape_string($_POST["cat_name"] );
    $cat_desc = mysql_real_escape_string($_POST["cat_desc"] );
    $cat_publish = mysql_real_escape_string($_POST["cat_publish"] );



    if(!empty($cat_name) && !empty($cat_desc)){

        $cat_check_name = "SELECT * from categories WHERE
                    cat_name = '$cat_name' and cat_id <> '$cat_id' ";
        $result_check_name = mysql_query($cat_check_name);
        $num_rows_all = mysql_num_rows($result_check_name);

            if($num_rows_all>0) {
                echo '6';
                exit();
            }
            //if categories are not out of number   
            else {
                $sql = "UPDATE  categories SET
                        cat_name = '{$cat_name}',
                        cat_description = '{$cat_desc}',
                            active = '{$cat_publish}'
                    WHERE
                        cat_id = {$cat_id}
                    ";
                $result_set = mysql_query($sql);

                if($result_set) echo '7';
                else echo '8';

                }
        }
        else echo '9';  
?>
4

0 回答 0