• 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
jquery
#1
Lightbulb 
با سلام
چرا این کد اجرا نمیشه
کد:
$(document).ready(function(){
    
    $("#save").click(function(){
        ajax("save");
    });

    $("#add_new").click(function(){
        $(".entry-form").fadeIn("fast");    
    });
    
    $("#close").click(function(){
        $(".entry-form").fadeOut("fast");    
    });
    
    $("#cancel").click(function(){
        $(".entry-form").fadeOut("fast");    
    });
    
    $(".del").live("click",function(){
        if(confirm("Do you really want to delete this record ?")){
            ajax("delete",$(this).attr("id"));
        }
    });

    function ajax(action,id){
        if(action =="save")
            data = $("#userinfo").serialize()+"&action="+action;
        else if(action == "delete"){
            data = "action="+action+"&item_id="+id;
            
            
        }
        
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data : data,
            dataType: "json",
            success: function(response){
                    alert(response);
                if(response.success == "1"){
                        
                    if(action == "save"){
                        $(".entry-form").fadeOut("fast",function(){
                            $(".table-list").append("<tr><td>"+response.fname+"</td><td>"+response.lname+"</td><td>"+response.email+"</td><td>"+response.phone+"</td><td><a href='#' id='"+response.row_id+"' class='del'>Delete</a></a></td></tr>");    
                            $(".table-list tr:last").effect("highlight", {
                                color: '#4BADF5'
                            }, 1000);
                        });    
                        $(".entry-form input[type='text']").each(function(){
                            $(this).val("");
                        });        
                    }else if(action == "delete"){
                        alert(12354);
                        var row_id = response.item_id;
                        $("a[id='"+row_id+"']").closest("tr").effect("highlight", {
                            color: '#4BADF5'
                        }, 1000);
                        $("a[id='"+row_id+"']").closest("tr").fadeOut();
                    }
                }else{
                    alert("unexpected error occured, Please check your database ");
                }
            },
            error: function(res){
                alert("Unexpected error! .");
            }
        });
    }
});

کد پی‌اچ‌پی:
<?php
error_reporting
(0);
include(
"config.php");
if(isset(
$_POST) && count($_POST)){
    
$fname mysql_real_escape_string($_POST['fname']);
    
$lname mysql_real_escape_string($_POST['lname']);
    
$email mysql_real_escape_string($_POST['email']);
    
$phone mysql_real_escape_string($_POST['phone']);
    
$item_id $_POST['item_id'];
    
$action $_POST['action'];

    if(
$action == "save"){
        
mysql_query("insert into info values('','".$fname."','".$lname."','".$email."','".$phone."')");
        
$lid mysql_insert_id();
        if(
$lid){
            echo 
json_encode(
                array(
                
"success" => "1",
                
"row_id" => $lid,
                
"fname" => htmlentities($fname),
                
"lname" => htmlentities($lname),
                
"email" => htmlentities($email),
                
"phone" => htmlentities($phone),
                )
            );
        }
        else{
            echo 
json_encode(array("success" => "0"));
        }
    }
    else if(
$action == "delete"){
    
        
$res mysql_query("delete from info where id = '".$item_id."'");
        if(
$res){
            echo 
json_encode(array( "success" => "1","item_id" => $item_id));
        }else{
            echo 
json_encode(array("success" => "0"));
        }
    }
}else{
    echo 
json_encode(array("success" => "0"));
    

  پاسخ
تشکر شده توسط :
#2
پیام خطایی؟ چیزی؟
همینطوری بگیم....Huh
سالهــــا مـــــى گــــــذرد، حادثه ها مى آید
انتظـــــار فـــــــرج از نیمـــــه خــــــرداد کشم

[عکس: ShowPicture.aspx?ID=52750d12-5d92-4286-9...height=100]
  پاسخ
تشکر شده توسط :


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان