I have the next class php:
class Job{
public $resultado;
public $busqueda;
public $wpdb;
public function __construct($busqueda){
global $wpdb;
$this->busqueda = $busqueda;
$this->resultado = array();
$this->wpdb = $wpdb;
}
public function search_job($resultado){
$tablepost =$this->wpdb->prefix.'posts';
$query = "SELECT * from $tablepost WHERE post_type = 'jobman_job' and post_status='publish';";
if (isset($wpdb)) {
global $wpdb;
$result = $wpdb->get_results($query);
}else{
$result = $this->wpdb->get_results($query);
}
print_r($result);
}
}
This found ok. Now I would like call the search_function with jQuery .ajax
I try with this:
(function($){
$('#searchjob').keypress(function(e){
var search = $.trim($('#searchjob').val());
if (e.which == "13") {
$.ajax({
beforeSend: function(){
//$('#loading').html(<img src="rutagif" alt="loading" />);
},
url:"../wp-content/themes/SUP2012/class/job.php",
data:{method: 'search_job', data:{resultado: 'hola'}},
type: "POST",
success: function(data){
}
});
};
});
})(jQuery);
the url parameters respond ok (200 OK), but not retrive information. Any idea?
To make an
ajax
request inwordpress
you should use infunctions.php
And the javascript should look like