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);
}
});
}
精彩评论