开发者

Not work my ajax call in function myalert()

I not know why not my ajax call on my function, did you can help me?

Example: http://jsfiddle.net/MaGyp/7/

function myalert() {
    var result = true;
        //var hide = $('.alert').fadeOut(100);
        //var css = $('#appriseOverlay').css('display','none');
        var $alertDiv = $('<div class="alert">Do you want to delete this item?<button class="ok">ok</button><button class="cancel">cancel</button></div>');
        $('body').append($alertDiv);
        $('.ok').click(function () {
            $('.alert').fadeOut(100);
            $('#appriseOverlay').css('display','none');
            callback(true);
        });
        $('.cancel').click(function () {
  开发者_StackOverflow社区          $('.alert').fadeOut(100);
            $('#appriseOverlay').css('display','none');
            callback(false);
        });
        $alertDiv.fadeIn(100);
        $('#appriseOverlay').css('display','block');
    return result;
    };

$('.iu').click(myalert)
function callback(result) {
    //
    if(result){
        alert(result);
        $('.image_upbg').each(function(){$(this).removeClass().addClass(unique())});
        var get_class = '.'+$(this).closest('div').attr('class');
        var get_val = $(this).closest('a').find('input').attr('value');
        //alert(get_val);
        var val = 'val_upimg1=' + get_val;
        $(get_class).fadeOut('slow');
          $.ajax({
                type: "POST",
                dataType: 'json',
                url: 'delete_upimg',
                data: val,
                cache: false,
                success: function (data) {
                        $(get_class).fadeOut('slow');
                },
                "error": function (x, y, z) {
                    // callback to run if an error occurs
                    alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
                }
       });
    }else{
        alert('no')
    }
}


this two lines causes problems

   var get_class = '.'+$(this).closest('div').attr('class');
   var get_val = $(this).closest('a').find('input').attr('value');

please add more html to your fiddle, or is it all?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜