I am trying to fetch few data from database in my .js file of wordpress theme. I tried with .post() of jquery but nothing is happening.
Please also suggest me any alternate.
code in .js file
jq.post("../abc.php",
{
name:"kumar",
accId:window.accommodationId
}, function(data,status)
{
alert("hello");
//alert("Data: " + data + "\nStatus: " + status);
}
);
code in abc.php file
<?php
global $wpdb;
$max_minAge = $wpdb->get_results( "SELECT price_per_day FROM wp_byt_accommodation_vacancies where accommodation_id='1741'" );
echo $max_minAge[0]->price_per_day;
?>
You can use the
jQuery AJAX get
shorthand:Good to know: Since you're getting data from a file, you should use a
GET
.you can use wp_ajax hooks like this in your functions.php file
Then add the ajax hook
then in your js file which you included via
enque_script
above. use thisjquery
click-on-this
will work when click on a link you can coomunicate on load or any other event