是的,有这样一种方法:你应该在那里通过绝对路径。。。
假设您的JS文件是这样排队的:
wp_enqueue_script( \'my-script\', \'path-to-js-file.js\'... );
那么你应该使用
wp_localize_script
并在其中传递值:
wp_localize_script( \'my-script\', \'MyScriptData\', array( \'ajax_url\' => site_url(\'/test/file.html\') ) );
然后,您可以通过以下方式访问JS文件中的该值:
return $.ajax({
type: \'get\',
dataType: \'html\',
url: MyScriptData.ajax_url, // <-- here you get that value...
success: function (resp) {
alert(‘Success’);
},
error: function (jqXHR) {
alert(\'Error ‘);
}
});
但是
You should know, that you SHOULD process AJAX requests using proper actions and not with some external file. Here you can read more about dealing with AJAX in WordPress: AJAX in Plugins