Question

When closing the Thickbox in Wordpress, I'm trying to first add the image selected via the Thickbox to the screen (working), and then run a small AJAX routine to update an option in the database (causing an error).

However, I'm getting the error NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument, and I don't know why.

Currently, all I'm doing is trying to test that the AJAX function is being pcicked up, so all the PHP function is doing is echo 'Working!';, so I'm fairly sure the problem is somewhere in the JS, as opposed to what's being returned by the PHP. However, commenting out the AJAX call does mean that the error does not appear.

Does anyone have any trouble-shooting suggestions? I am very lost as to where to look at the moment. Thanks.

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);

            });

        }

    }

});

Thanks,

Was it helpful?

Solution

Take a look at this:

data = {
                security: $('input#_wpnonce', '#dd-options-edit-office-page'),
                action: 'update-office-image'
            };

data.security contains a jQuery-object, it's not possible to send this object.

I guess you like to send the value of the input:

data = {
                security: $('input#_wpnonce', '#dd-options-edit-office-page').val(),
                action: 'update-office-image'
            };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top