阿贾克斯按一下按钮,触发一个PHP文件/链接 [英] Ajax button click that triggers a php file / link
本文介绍了阿贾克斯按一下按钮,触发一个PHP文件/链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个简单的按钮,当我点击,它显示了一个文件中的内容为file.php
(当它触发该文件显示了一个随机数),如果它点击数次刷新从内容为file.php
。
I want a simple button that when I click, it shows the content from a file file.php
( this file when triggered it shows a random number) and if it's clicked several times refreshes the content from file.php
.
推荐答案
您可以尝试这样的:
PHP文件:为file.php
PHP File: 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>
我希望这是你所问。
I hope this is what you are asking.
编码快乐!
这篇关于阿贾克斯按一下按钮,触发一个PHP文件/链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文