【发布时间】:2015-10-06 01:52:07
【问题描述】:
我需要获取客户详细信息(个人资料页面上提供的客户数据)并在需要时将其填充到 Gravity Form 表单中。
到目前为止,我意识到我需要类似here 描述的东西,但由于某种原因,我的 javascript 没有按预期返回数据。这是我的代码:
jQuery(document).ready(function() {
// form pre-population when "I am the Insured* entity" checkbox is checked
if ( !globals.logged_in ) {
jQuery('li#field_1_160').remove();
} else {
jQuery('#choice_1_160_1').change(function() {
console.log('customer data: change ');
if(jQuery(this).is(":checked")) {
console.log('customer data: checked ');
var data = {
user_id: globals.userID,
type_to_load: 'billing',
action: 'woocommerce_get_customer_details',
// security: woocommerce_admin_meta_boxes.get_customer_details_nonce
};
jQuery.ajax({
url: globals.ajax_url,
data: data,
type: 'POST',
success: function( response ) {
var info = response;
console.log('customer data: ' + response);
},
error: function() {
console.log('An error occurred');
}
});
} else {
console.log('customer data: unchecked ');
}
});
}
});
这是我单击复选框时在控制台中看到的内容(id 选择_1_160_1):
wpchris.com.js?ver=1.0:68 customer data: change
wpchris.com.js?ver=1.0:71 customer data: checked
wpchris.com.js?ver=1.0:87 customer data: -1
我认为问题出在我注释掉的那一行:
// security: woocommerce_admin_meta_boxes.get_customer_details_nonce
我这样做是因为它遇到了错误:
Uncaught ReferenceError: woocommerce_admin_meta_boxes is not defined
我在 Woocommerce 代码中看到它在少数地方使用 woocommerce_admin_meta_boxes 对象(例如在 woocommerce\assets\js\admin\meta-boxes-order.js:119 中),但由于某种原因我不能。
任何帮助将不胜感激。
【问题讨论】:
-
请看一眼?
标签: jquery ajax wordpress woocommerce