我有頁面index.php
上的提交按鈕當我單擊此按鈕時,通過ajax調用另一個腳本(call.php)
,該腳本包含一些響應。現在我希望通過ajax腳本的調用,點擊提交按鈕和在div下顯示/接收的響應之間的時間,應該禁用按鈕選項1和選項2。當成功顯示結果時,2個按鈕應該啓用,但是我無法這樣做。誰能幫助我與它單擊按鈕後禁用2個按鈕
3個按鈕和腳本代碼index.php頁面上
<button class="rightbtn" type="button" id="submitamt" style="display:none; ">Submit</button>
<a href="#popup"><button class="botleftbtn" type="button" id="walkaway" style="display:none">Option1</button></a>
<a href="#"><button class="botrightbtn" type="button">Option2</button></a>
<script>
function myFunction() {
alert("You need to login before negotiating! However you can purchase the product without negotiating");
}
var startClock;
var submitamt;
var walkaway;
var digits;
$(function() {
startClock = $('#startClock').on('click', onStart);
submitamt = $('#submitamt').on('click', onSubmit);
walkaway = $('#walkaway').on('click', onWalkAway);
digits = $('#count span');
beforeStart();
});
var onStart = function(e) {
startClock.fadeOut(function() {
startTimer();
submitamt.fadeIn(function() {
submitamt.trigger('click'); // fire click event on submit
});
walkaway.fadeIn();
});
};
var onSubmit = function(e) {
var txtbox = $('#txt').val();
var hiddenTxt = $('#hidden').val();
$.ajax({
type: 'post',
url: 'call.php',
dataType: 'json',
data: {
txt: txtbox,
hidden: hiddenTxt
},
cache: false,
success: function(returndata) {
$('#proddisplay').html(returndata);
},
error: function() {
console.error('Failed to process ajax !');
}
});
};
var onWalkAway = function(e) {
//console.log('onWalkAway ...');
};
var counter;
var timer;
var startTimer = function() {
counter = 120;
timer = null;
timer = setInterval(ticker, 1000);
};
var beforeStart = function() {
digits.eq(0).text('2');
digits.eq(2).text('0');
digits.eq(3).text('0');
};
var ticker = function() {
counter--;
var t = (counter/60) | 0; // it is round off
digits.eq(0).text(t);
t = ((counter % 60)/10) | 0;
digits.eq(2).text(t);
t = (counter % 60) % 10;
digits.eq(3).text(t);
if (!counter) {
clearInterval(timer);
alert('Time out !');
resetView();
}
};
var resetView = function() {
walkaway.fadeOut();
submitamt.fadeOut(function() {
beforeStart();
startClock.fadeIn();
});
};
</script>