[英]Execute PHP script onclick with jQuery
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: 我正在尝试让jQuery为我执行PHP脚本,此刻看起来非常像这样:
html HTML
<button id="element">Click me!</button>
php PHP
$string = "Hello Earth!";
echo $string;
jQuery jQuery的
$('#element').click(function() {
$.load('.../script.php', function(e){
console.log(e);
});
});
.load()
must be called on an element, like this: .load()
必须在元素上调用,如下所示:
$('#element').click(function() {
$('#element').load('.../script.php', function(e){
console.log(e);
});
});
The load() method loads data from a server and puts the returned data into the selected element . load()方法从服务器加载数据, 并将返回的数据放入所选元素 。 from http://www.w3schools.com/jquery/jquery_ajax_load.asp
来自http://www.w3schools.com/jquery/jquery_ajax_load.asp
Correct sintax: 正确的sintax:
$( "#result" ).load( "ajax/test.html" );
And you have to correct your code, you have .../script.php instead of ../script.php 而且您必须更正代码,而使用... / script.php而不是../script.php
<button id="element">Click me!</button>
<?php $string = "Hello Earth!"; echo $string; ?>
$('#element').live('click',function() {
$.ajax({
method:'POST',
success:fuction(data){
'your coe here';
}
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.