用jQuery执行PHP脚本onclick [英] Execute PHP script onclick with jQuery
本文介绍了用jQuery执行PHP脚本onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我正在努力使这个工作:
我试图让jQuery为我执行一个PHP脚本,目前它看起来很漂亮很像这样:
html
< button id =元素>点击我!< / button>
php
$ string =Hello Earth!;
echo $ string;
<$点击(函数(){
$ .load('... / script.php',函数(e){
console.log(e) );
});
});
解决方案
.load()
必须在元素上调用,如下所示:
$('#element')。click函数(){
$('#element')。load('... / script.php',function(e){
console.log(e);
}) ;
});
Hello I'm struggling to get this to work:
I'm trying to get jQuery to execute a PHP Script for me, at the moment it looks pretty much like this:
html
<button id="element">Click me!</button>
php
$string = "Hello Earth!";
echo $string;
jQuery
$('#element').click(function() {
$.load('.../script.php', function(e){
console.log(e);
});
});
解决方案
.load()
must be called on an element, like this:
$('#element').click(function() {
$('#element').load('.../script.php', function(e){
console.log(e);
});
});
这篇关于用jQuery执行PHP脚本onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文