0

WordpressでThickboxを閉じるとき、最初にThickboxを介して選択した画像を画面に追加して(動作中)、小さなAJAXルーチンを実行してデータベース内のオプションを更新しようとしています(エラーが発生します)。

ただし、エラーが発生NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argumentし、理由がわかりません。

現在、私が行っているのは、AJAX 関数がピックアップされていることをテストしようとしているだけなので、PHP 関数が実行しているecho 'Working!';のは . 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);

            });

        }

    }

});

ありがとう、

4

1 に答える 1

1

これを見てください:

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

data.securityjQuery オブジェクトが含まれている場合、このオブジェクトを送信することはできません。

入力の値を送信するのが好きだと思います:

data = {
                security: $('input#_wpnonce', '#dd-options-edit-office-page').val(),
                action: 'update-office-image'
            };
于 2013-01-02T13:18:39.663 に答える