在我的php中,我有这个:
<?php
@include_once('fields.php');
$gg = fetchinfo("val","inf","n","current");
$mm = fetchinfo("val","info","n","max");
$cc = fetchinfo("num","games","id",$gg);
$percent = $cc / $mm *100;
echo'<input class="knob" id="progress-circle" data-fgcolor="#f15700" data-bgcolor="rgba(23,28,34,0.8)" data-min="'.$cc.'" data-max="'.$mm.'" data-thickness=".2" readonly="readonly" value="'.$cc.'" data-width="18%" style="width: 142px; height: 92px; position: absolute; vertical-align: middle; margin-top: 92px; margin-left: -209px; border: 0px; font-style: normal; font-variant: normal; font-weight: bold; font-stretch: normal; font-size: 69px; line-height: normal; font-family: Arial; text-align: center; color: rgb(241, 87, 0); padding: 0px; -webkit-appearance: none; background: none;">';
?>
我有一个js文件,当velue用以下代码更改时,我想刷新和更改它:
refresh();
function refresh()
{
$.ajax({
type: "GET",
url: "pro.php",
error: function(err) {
console.log(err);
},
success: function(result) {
$("#progress-circle").val(result).trigger('change');
}
});
setTimeout(refresh, 1000);
}
但是当值改变时,它在我的html中不会改变,它只在我刷新页面时更新。
使用jQuery的val()
时,应该只更新value属性。如果您提供了整个html节点,它就不起作用。
您可以在$percent = ...
和echo
之间插入此内容来更新您的php
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
// Kein AJAX-Request, der passende Header fehlt
echo $percent;
exit;
}