我有一个AJAX功能如下。代码有一些我不知道如何解决的错误。我想要做的是,每次我点击一个按钮(仅一次),它会立即将该按钮的值保存到数据库中,但发生了什么,它要求用户点击两次以保存值那个按钮。有没有人可以帮助我,因为我是AJAX和jQuery的新手?感谢!!!
HTML
<fieldset>
<input type="radio" id="start2'+i+'" name="oris'+i+'" value="2" onClick="get(id,2);">
<input type="radio" id="start1'+i+'" name="oris'+i+'" value="1" onClick="get(id,1);">
</fieldset>
AJAX
function get(startId){
var objectA = parseInt(startId.substr(4,1));
var id = parseInt(startId.substr(5,1));
var idNumber = "<?php echo $_GET['idNumber']; ?>";
$('#start'+objectA+id).click(function(){
jQuery.ajax({
url: 'followingPage.php',
type: 'post',
data: {" field1value": + objectA, "idNumber": + idNumber, "id": +id },
success: function(results){
top.location="submission.php?idNumber=<?=$_GET['idNumber'];?>";
}
});
});
}
答案 0 :(得分:0)
$(function(){
$("input[type='radio']").click( function() {
var idNumber = "<?php echo $_GET['idNumber']; ?>";
jQuery.ajax({
url: 'followingPage.php',
type: 'post',
data: {" field1value": + $(this).val(), "idNumber": + idNumber, "id": + $(this).attr("id") },
success: function(results){
top.location="submission.php?idNumber=<?=$_GET['idNumber'];?>";
}
});
});
}
这样的东西?
答案 1 :(得分:0)
HTML部分添加
<form onSubmit="return false;" >
</form>
答案 2 :(得分:0)
var flag = false;
$('#start'+objectA+id).click(function(){
if(flag){ return false; } //prevent multiple click
flag = true;
//do your stuff here
});