SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why not work success: function()?(jquery.ajax)

    hello
    why not work success: function()?(jquery.ajax)
    Code:
    success: function(){
     $(this).fadeOut("slow",function(){
     $(this).parent().remove();
     });
     }

  2. #2
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That function is being called without a jquery object, so variable "this" is undefined.

    I suggest to assign some id to your item and then using that id in handler.

  3. #3
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!
    My problem was solved.this code ok?
    Code:
    $('.tableeven tr').hover(function(){
            $(this).addClass('over');
        }, function(){
            $(this).removeClass('over');
        }).click(function(){
            checkBox = $(this).find("input").attr('checkbox', 'checked');
            $id = $('input:checkbox:checked').val();
            if (checkBox.attr('checked')) {
                $(this).css('backgroundColor', "");
                checkBox.attr('checked', '');
            }
            else {
                checkBox.attr('checked', 'checked');
                $(this).css('backgroundColor', "#140d01");
            }
        });
        $('#delete_i').click(function(){
            $('.chk').each(function(){
                if ($(this).attr('checked')) {
                    var dataString = 'checkbox=' + $('input:checkbox:checked').val();
                    $(this).parent().parent().fadeOut("slow");
                    var self = this;
                    $.ajax({
                        type: "POST",
                        url: "http://localhost/parsdiba/index.php/admin/customer_size/delete",
                        data: dataString,
                        cache: false,
                        success: function(){
                        },
                        error: function(data){
                            alert('Load was performed.');
                        }
                    })                
                }
            })
        });

  4. #4
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should use prop('checked') instead of attr('checked') and prop('checked', true) instead of attr('checked', 'checked') if you are using jQuery 1.6 or newer version.

    This line is useless because you aren't using variable "self":
    Code:
    var self = this;
    Other than that, code seems to be ok.

  5. #5
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1- .prop() right used?
    2- How do I change the code for delete multiple rows from mysql?
    Code:
        $('.tableeven tr').hover(function(){
            $(this).addClass('over');
        }, function(){
            $(this).removeClass('over');
        }).click(function(){
            checkBox = $(this).find("input").prop('checkbox', 'checked');
            $id = $('input:checkbox:checked').val();
            if (checkBox.prop('checked')) {
                $(this).css('backgroundColor', "");
                checkBox.prop('checked', '');
            }
            else {
                checkBox.prop('checked', 'checked');
                $(this).css('backgroundColor', "#140d01");
            }
        });
        $('#delete_i').click(function(){
            $('.chk').each(function(){
                if ($(this).prop('checked')) {
                    var dataString = 'delete[]=' + $('input:checkbox:checked').val();
                    $(this).parent().parent().fadeOut("slow");
                    $.ajax({
                        type: "POST",
                        url: "http://localhost/parsdiba/index.php/admin/customer_size/delete",
                        data: dataString,
                        cache: false,
                        success: function(){
                        },
                        error: function(data){
                            alert('Load was performed.');
                        }
                    })                
                }
            })
        });

  6. #6
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. No, second parameter is ether true or false, not 'checked'

  7. #7
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CyberAlien View Post
    1. No, second parameter is ether true or false, not 'checked'
    Please answer to question 2.
    Now it is right?
    Code:
    else {
                checkBox.prop('checked', 'true');
                $(this).css('backgroundColor', "#140d01");
            }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •