Sunday, April 14, 2019

How to use ajax with google api jquery library

Here is the code of


<script>
        function insert_update_category(id)
        {

             //alert("OK");
            var category_name = $("#category_name").val();
            var category_details = $("#category_details").val();


            if(category_name =='')
            {
               $("#category_name_error").show();
            }
            else
            {
           
             $.ajax({
                    method: "get",
                    url: 'category_submit.php',
                    data: {id: id,category_name: category_name,category_details: category_details}
                })
                .done(function (response)
                {

                    if(response==1)
                    {
                        if(id >0)
                        {
                            alert("Category update successfully.");
                            //category_edit(id);
                        }
                        else
                        {
                            alert("Category inserted successfully.");
                            //show_category_form();
                        }
                        show_category_form();
                        show_category_list();
                       
                    }
                    else
                    {
                        alert("something wrong");

                    }

                    //alert(response);
                    //$("#category_list").html(response);
                });
            }   
           
         }



         function show_category_form()
         {

            var id = "";

            $.ajax({
                    method: "get",
                    url: 'category_form.php',
                    data: {id: id}
                })
                .done(function (response)
                {

                   
                    $("#category_form").html(response);
                });

         }



         function show_category_list()
         {

            var id = "";

            $.ajax({
                    method: "get",
                    url: 'category_list.php',
                    data: {id: id}
                })
                .done(function (response)
                {

                   
                    $("#category_list").html(response);
                });

         }




         function category_edit(id)
         {

            //alert(id);

            //var id = "";

            $.ajax({
                    method: "get",
                    url: 'category_edit.php',
                    data: {id: id}
                })
                .done(function (response)
                {

                    //alert(response);
                   
                    $("#category_form").html(response);
                });

         }



         function category_delete(id)
         {

            //var id = "";

            $.ajax({
                    method: "get",
                    url: 'category_delete.php',
                    data: {id: id}
                })
                .done(function (response)
                {

                if(response==1)
                {
                alert("Category deleted successfully.");
                     
                        show_category_list();
                        show_category_form();
                }
                else
                {
                alert("something wrong.");
                }
                 
                       
                   

                });

         }
       


         function blank_me(id)
         {
            var val =   $("#"+id).val();

            var error_id = id +"_error";

            //alert();

            if(val !="")
            {
                $("#"+error_id).hide();
            }
            else
            {
                $("#"+error_id).show();
            }
         }

</script>

No comments:

Post a Comment