开发者

jquery - live and delegate failed here

开发者 https://www.devze.com 2023-03-29 22:43 出处:网络
The following codes worked before but would not work again except I put alert after the ajax call, I\'ve开发者_C百科 use both delegate & live but it didn\'t work still.

The following codes worked before but would not work again except I put alert after the ajax call, I've开发者_C百科 use both delegate & live but it didn't work still.

function getAns(val) {
var value;
value = $("input[name=ans"+val+"]:checked").val();
$.post('ajax.php', {val:value}, function(data) {
    alert(data);
});
//only works with this alert
alert('done'); 
});

}


Looks like you had an additional }); in your function. You are also using val as an object key when it holds a value from the function argument. Not sure if that was intentional, but try this:

function getAns(_val) {

    $.ajax({
        url: 'ajax.php',
        data: 'val=' + $("input[name=ans" + _val + "]:checked").val(),
        type: 'post',
        success: function(data){
            alert(data);
        },
        error: function(jqXHR, textStatus, errorThrown){
            alert(textStatus + ' -- ' + errorThrown);
        }
    });
}
0

精彩评论

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