我正在制作这个AJAX电话。如何让这个JQuery刷新/重新加载正在调用的脚本并在之后执行AJAX调用。如果用户再次重新点击同一按钮并显示新数据,我想使用它。
问题:
当点击aht_button时它会返回数据,但是如果我刷新页面并且我再次点击按钮它仍会显示旧数据。我必须手动刷新我的" show_aht.php"在我的浏览器上然后点击" aht_button"所以我可以显示从" show_aht.php"中检索到的新数据。
提前感谢!
JS:
<div id="aht">
<button id="aht_button">AHT</button>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#aht').click(function(){
$.ajax({
type:"GET",
url : "show_aht.php",
data:{ } ,
dataType: 'json',
success : function(data){
//get the MIN value from the array
var min = data.reduce(function(prev, curr) {
return isNaN(+curr['aht_value']) || prev < +curr['aht_value'] ? prev : +curr['aht_value'];
}, 1000000);
alert("min:" + min);
//get the MAX value from the array
var max = data.reduce(function(prev, curr) {
return isNaN(+curr['aht_value']) || prev > +curr['aht_value'] ? prev : +curr['aht_value'];
}, -1000000);
alert("max:" + max);
//function for calculation of background color depending on aht_value
function conv(x){
return Math.floor((x - min) / (max - min) * 255);
}
//function for background color, if NA then show white background, either show from green to red
function colorMe(v){
return v == 'NA' ? "#FFF" : "rgb(" + conv(v) + "," + (255-conv(v)) + ",0)";
}
//going through all DIVs only once with this loop
for(var i = 0; i < data.length; i++) { // loop over results
var divForResult = $('#desk_' + data[i]['station']); // look for div for this object
if(divForResult.length) { // if a div was found
divForResult.html(data[i]['aht_value']).css("background-color", colorMe(data[i]['aht_value']));
}//end if
}//end for
}//end success
});//end ajax
});//end click
});//end rdy
</script>
答案 0 :(得分:0)
您可以使用url哈希进行重定向,并在页面重新加载后捕获它们
window.location = window.location + "#do=ajax";
// after page load
$(document).ready(function () {
var hash = window.location.toString().split("#")[1];
// cases
});