【发布时间】:2019-05-21 20:05:26
【问题描述】:
我在 Wordpress 上有一个 ajax 问题。 我有一个简单的 Select 按钮,它有一个使用 ajax 的 onclick 功能。 该函数调用一个名为 ajax-filter-system.php 的文件,该文件具有一个简单的字符串“HELLO WORLD”,使用类“ajax-loader”重新加载 div 内容,在末尾打印“HELLO WORD0”和“0”细绳。无法理解为什么... 有代码:
函数.php
add_action('wp_ajax_load_specialita', 'load_specialita_ajax_handler');
add_action('wp_ajax_nopriv_load_specialita', 'load_specialita_ajax_handler');
function load_specialita_ajax_handler() {
require(get_stylesheet_directory().'/assets/ajax/ajax-filter-system.php');
}
ajax-filter-system.php
<div>Hello World</div>
函数onclick(js文件)
function showSpecialita() {
jQuery(function($) {
var select_target = "";
var select_target = $('#specialita-selected').val(); // <select> ID
var xhttp;
$.ajax({
url : 'https://www.mysite.it/wp-admin/admin-ajax.php', // AJAX handler
data : { action : 'load_specialita', specialita : select_target },
type : 'POST',
success : function( result ){
if( result ) {
$('.ajax-loader-specialita').html(result);
}
}
});
});
}
如果我改变了
$('.ajax-loader-specialita').html(result);
在
$('.ajax-loader-specialita').html('Hello Word');
一切正常
非常感谢!
【问题讨论】:
标签: javascript ajax wordpress