Code来自functions.php s.php
function university_files()
{
wp_localize_script('main-university-js', 'universityData', array(
'root-url' => get_site_url()
));
};
add_action('wp_enqueue_scripts', 'university_files');
来自JS的<#>Code
getResults() {
$.getJSON(
universityData.root_url +
"/wp-json/wp/v2/posts?search=" +
this.searchField.val(),
(posts) => {
this.resultsDiv.html(`
General Information
${
posts.length
? ``
: `No General Information Marched your search`
}
${posts
.map(
(item) =>
`${item.title.rendered}`
)
.join("")}
${posts.length ? `` : ""}
`);
this.isSpinnerVisible = false;
}
);
}
发布于 2022-08-07 18:50:59
因为你有:
universityData.root_url
但你本地化了:
'root-url' => get_site_url()
root_url
!= root-url
https://wordpress.stackexchange.com/questions/408365
复制相似问题