$.post(ajaxurl,{
action:\'master_ajaxurl\',
option: $(this).find("option:selected").val(), // use option also here
},
function(data){
//adds the echoed response to our container
// alert(data);
$("#details").html(data);
}
);
将动作和功能移动到功能中。php文件
按注释进行一些更改
add_action(\'wp_ajax_master_ajaxurl\', \'master_ajaxurl\');
add_action(\'wp_ajax_nopriv_master_ajaxurl\', \'master_ajaxurl\');
function master_ajaxurl() {
$myOpt = $_POST[\'option\']; // use option instead of data
echo bringDetails($myOpt);
die();
}
<小时>
**page.php**
$(document).ready(function () {
var ajaxurl = \'----admin_url----\';
$(\'#combobox\').click(function(){
$.post(ajaxurl,{
action:\'master_ajaxurl\',
option: data to send, // key => value
option2: \'hello\'
},
function(data){
//adds the echoed response to our container
alert(data);
//$("#details").html(data);
}
);
});
});
**functions.php**
function master_ajaxurl() {
$myOpt = $_POST[\'option\'];
echo bringDetails($myOpt);
die();
}
must use echo and die() in your ajax output function.
this is working for me. Hope this works now.