我想要一个简单的按钮,当我点击它时,它会显示文件file.php
中的内容(此文件在被触发时会显示一个随机数),如果它被点击多次,则刷新内容来自file.php
。
答案 0 :(得分:0)
您可以尝试这样的事情:
PHP文件: file.php
<?php
//your php code for random number...
?>
HTML文件:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<input type="button" id="clkMe" value="Load File" />
<div id="response"></div>
<script>
$(document).ready(function(){
$("#clkMe").click(function(){
var dataString={};
$.ajax({
url:"file.php",
type: 'POST',
cache:false,
data: dataString,
beforeSend: function() {},
timeout:10000,
error: function() { },
success: function(response) {
$("#response").html(response);
alert(response);
}
});
});
});
</script>
</body>
</html>
我希望这就是你所要求的。
快乐编码!!!