正如我提到的here 这两个ajax操作,下面是如何使用第二个操作以db格式提取表单值
创建将返回设置选项的ajax操作
您可以将此代码添加到{theme}/functions.php
或至{theme}/inc/hooks.php
function _action_ajax_fw_theme_get_settings_options() {
wp_send_json_success(array(
\'options\' => fw()->theme->get_settings_options()
));
}
add_action( \'wp_ajax_fw_theme_get_settings_options\', \'_action_ajax_fw_theme_get_settings_options\' );
打开
Theme Settings 分页并在控制台中运行此脚本
var dbSettingsOptions = {
$form: jQuery(\'.fw-settings-form\'),
options: null,
getOptions: function (callback) {
if (this.options) {
return callback(this.options);
}
jQuery.ajax({
url: ajaxurl,
type: \'POST\',
data: \'action=fw_theme_get_settings_options\',
dataType: \'json\',
success: _.bind(function (response, status, xhr) {
if (!response.success) {
alert(\'Ajax error\');
return;
}
this.options = response.data.options;
callback(this.options);
}, this),
error: function (xhr, status, error) {
alert(\'Ajax error\');
}
});
},
getValues: function(callback) {
if (!this.options) {
return this.getOptions(_.bind(function(){
this.getValues(callback);
}, this));
}
jQuery.ajax({
url: ajaxurl,
type: \'POST\',
data: [
\'action=fw_backend_options_get_values\',
this.$form.serialize()
.replace(/fwf=[^\\&]+\\&/, \'\'), // remove special hidden input value to prevent form save
\'options=\'+ encodeURIComponent(JSON.stringify(this.options))
].join(\'&\'),
dataType: \'json\',
success: _.bind(function (response, status, xhr) {
if (!response.success) {
alert(\'Error: \'+ response.data.message);
return;
}
callback(response.data.values);
}, this),
error: function (xhr, status, error) {
alert(status +\': \'+ error.message);
}
});
}
};
dbSettingsOptions.getValues(function(values){ console.log(values); });