Clicking on div #some_id calls details.php but it doesn't succeed in retrieving data from jQuery. details.php is supposed to echo 123.
My goal is that when I click on div #some_id, details.php shows 123 in the browser.
html:
<div id="some_id">
<a href="details.php"> Details </a>
</div>
jQuery:
function detailsClick(){
$("#some_id").live('click', function(){
var data = {'myData': 123};
$.post('details.php', data);
});
}
details.php:
<?php
$idNumber = $_POST["myData"];
echo ($idNumber);
?>
I believe that you are not getting click event here. Change jQuery code as below.
$(function(){
$("#some_id").on('click', function(){
var data = {'myData': '123'};
$.post( "details.php", data)
.done(function( data ) {
alert( "Data Loaded: " + data );
});
});
});
.live() is deprecated. Use .on() instead.detailsClick() is never called. So the onclick listener is NOT registered.Either do this.
function detailsClick(){
$("#some_id").live('click', function(){
var data = {'myData': 123};
$.post('details.php', data);
});
}
detailsClick();
OR do this..
$(document).ready(function(){
$("#some_id").live('click', function(){
var data = {'myData': 123};
$.post('details.php', data);
});
});
ALSO, you need to use AJAX for what you want to do.
Refer AJAX with jQuery()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With