Reputation: 5929
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);
});
});
Upvotes: 0
Views: 7976
Reputation: 159
<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';
}
})
});
Upvotes: 0
Reputation: 1361
The load() method loads data from a server and puts the returned data into the selected element. from http://www.w3schools.com/jquery/jquery_ajax_load.asp
Correct sintax:
$( "#result" ).load( "ajax/test.html" );
And you have to correct your code, you have .../script.php instead of ../script.php
Upvotes: 1
Reputation: 5685
.load()
must be called on an element, like this:
$('#element').click(function() {
$('#element').load('.../script.php', function(e){
console.log(e);
});
});
Upvotes: 3