在Wordpress中关闭Thickbox时,我试图首先将通过Thickbox选择的图像添加到屏幕(工作),然后运行一个小的AJAX例程来更新数据库中的选项(导致错误)。
但是,我收到错误NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument
,我不知道原因。
目前,我所做的只是尝试测试AJAX函数正在进行测试,所以所有PHP函数都在做echo 'Working!';
,所以我很确定问题出在JS的某个地方,而不是PHP返回的内容。但是,注释掉AJAX调用确实意味着错误没有出现。
有没有人有任何解决问题的建议?我很遗憾在哪里看当下。感谢。
jQuery(document).ready(function($){
window.send_to_editor = function(html){
/** Grab the image URL and image ID */
var image_url = $('img', html).attr('src'),
classes = $('img', html).attr('class'),
id = classes.replace(/(.*?)wp-image-/, '');
/** Add the imgae ID to a hidden field, so that it can be saved */
$('#office-image input#image-id').val(id);
/** Remove the Thickbox */
tb_remove();
/** Place the image src in the hidden image, and then show the image */
$('#office-image img#image-preview').attr('src', image_url);
$('#office-image img#image-preview').css('display', 'block');
$('#office-image img#image-preview').css('margin-bottom', '5px');
/** Check to see if the user is editing an Office, and if they are, update the Image in the database */
if($('#dd-options-edit-office-page').length) {
/** Set the params for passing to the AJAX function */
data = {
security: $('input#_wpnonce', '#dd-options-edit-office-page'),
action: 'update-office-image'
};
$.post('admin-ajax.php', data, function(response){
alert(response);
});
}
}
});
谢谢,
答案 0 :(得分:1)
看看这个:
data = {
security: $('input#_wpnonce', '#dd-options-edit-office-page'),
action: 'update-office-image'
};
data.security
包含一个jQuery对象,无法发送此对象。
我想你想发送输入的值:
data = {
security: $('input#_wpnonce', '#dd-options-edit-office-page').val(),
action: 'update-office-image'
};