Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here i am sending the ajax response to load_post.php page from my ajax call.I am getting response on load_post.php on load_post.php i have to fire word press query.

I was try this but getting bellow error in response.when i add global $wpdb variable into load_post.php file

Parse error</b>:  syntax error, unexpected T_GLOBAL in <b>/home/skovianc/public_html/test/thefoodieclub.com/wp-content/plugins/woocommerce-booking/load_post.php

ajax code

var time=0;
jQuery("#time_slot").change(function()
                                {   
                                time=time_slot.value;
                            $.post("'. plugins_url().'/woocommerce-booking/load_post.php",
                                 {name: time},
                                  function(response){
                                  console.log(response);
                                  }
                                );  
                                 }); 

post url file load_post.php code here i want fire wpdb query

<?php session_start();
    echo $name= $_POST["name"];
    file_put_contents("name.txt", $name)

//Query will be some thing like

global $wpdb;
echo $query = $wpdb->prepare( "SELECT start_date FROM {$wpdb->prefix}booking_history");


 ?>

So how can fire query on ajax post url page load_post.php

share|improve this question
    
Your error is because you execute load_post.php expecting Wordpress engine be loaded in that but it is obviously not. Please, refer to Wordpress Ajax API any of the several questions about how to use Ajax in Wordpress. –  cybmeta Jul 21 at 8:06
    
is there any way with this what i am looking for –  Sanjay Nakate Jul 21 at 8:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.