2016-04-27 116 views
1

我是jquery的初學者。請幫我解決我的任務。如何停止重複請求jquery?

我有形式選擇和行動的onfocus作品在我的代碼:

function sendBall(id){ 
$('#bal_'+id).blur(function(){ 
$.ajax({ 
type: "POST", 
url: "<?php echo Yii::$app->createUrl("teacher/setball");?>", 
data: {shedId: this.form.shedId.value, type: this.form.type.value, userId: this.form.userId.value, ball: this.form.bal.value}, 
error: function(){ 
}, 
beforeSend: function(){ 
    $('select').attr('disabled'); 
    $('#bal_'+id).unbind('focus'); 
}, 
success: function(data){ 
    $('select').removeAttr('disabled'); 
} 
}); 
}); 
} 

我想給每個事件一個請求。

+0

沒有從上面得到你要求的東西。上面的代碼會在模糊時觸發請求。 – Hardik

回答

0
$show.='<form id="theForm_' . $ruzId . $uId . '">'; 
    $show.=CHtml::hiddenField('type', $ruzId, array('id' => 'type')); 
    $show.=CHtml::hiddenField('shedualId', $idShedual, array('id' => 'shedId')); 
    $show.=CHtml::hiddenField('userId', $groupIn, array('id' => 'userId')); 
    $show.=CHtml::dropDownList('bal', 'text', array(0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array('onfocus' => 'sendBall(' . $ruzId . $groupIn . ')','id' => 'bal_' . $ruzId . $groupIn,'empty'=>' ')); 
    $show.=' <button type="button" class="delete classHidden" onfocus="dellBall(' . $ruzId . $groupIn . ')" id="delete_' . $ruzId . $groupIn . '">×</button>'; 
    $show.='</form>'; 
    $show.='</td>';