我有下一个类 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);
}
}
这发现没问题。现在我想用 jQuery .ajax 调用 search_function 我试试这个:
(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);
url 参数响应正常(200 OK),但不检索信息。任何的想法?