As I try to close the Thickbox in my Wordpress site after selecting an image, I encounter an issue that involves adding the selected image to the screen successfully, followed by running a small AJAX routine to update a database option, which triggers an error.
The error message I receive is
NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument
, and I am struggling to identify the root cause.
Currently, I am only trying to test if the AJAX function is functioning correctly. The PHP function simply echo 'Working!';
, indicating that the issue may lie within the JavaScript code rather than the PHP output. However, the error does not occur when I comment out the AJAX call.
Could anyone provide suggestions for troubleshooting? I am feeling quite lost and unsure where to focus my attention. Thank you in advance.
jQuery(document).ready(function($){
window.send_to_editor = function(html){
/** Extract 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 image ID to a hidden field for saving purposes */
$('#office-image input#image-id').val(id);
/** Close the Thickbox */
tb_remove();
/** Set the image source in the hidden image and display it */
$('#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 if the user is editing an Office and update the Image in the database accordingly */
if($('#dd-options-edit-office-page').length) {
/** Define the parameters for 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);
});
}
}
});
Thank you,