Error NS_ERROR_XPC_BAD_CONVERT_JS occurred while attempting to execute an AJAX function

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,

Answer №1

Check out this code snippet:

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

The variable data.security currently holds a jQuery object, which cannot be sent as is.

It seems like you want to send the value of the input instead:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jQuery divs seem to "gaze up" towards the mouse pointer

I am attempting to recreate a fascinating effect using jQuery - where "cards" move in response to the mouse cursor as if they are looking up at it. I have come across a script that almost achieves what I need, but I require the ability to control the mov ...

How can I attach an existing event to a dynamically loaded element using AJAX?

In the main page of my website, there is a button: <button class="test">test</button> Additionally, I have included the following script in my code: $('.test').on('click',function(){ alert("YOU CLICKED ME"); } ...

Combining Key-Value pairs in JavaScript using JSON

I am currently working on parsing a JSON object to extract the key and value combined into a variable. The desired output I want from the provided JSON is: "/" - 7.84 GiB; "/opt" - 4.86 GiB; "/usr" - 4.80 GiB While I can retrieve objects using my code sn ...

Repairing the orientation in unique threejs capsule geometric shape

Exploring the realm of custom geometry in three.js, I decided to experiment with modifying Paul Bourke's capsule geometry example. However, as I delve into creating my own custom capsule geometry, I have encountered two main challenges: The orienta ...

Utilizing arrays to populate a line graph in Highcharts

I am struggling to figure out how to incorporate data from an array obtained from another function in my javascript file into my line graph. I want to confirm that this is feasible without switching to a different graphing package. Below is my current co ...

Disappearing act: The vanishing act of the Bootstrap 4 Smart Scroll Mobile

Utilizing the Smart Scroll feature from in Bootstrap has been successful on desktop, but issues arise on mobile devices. When scrolling down and returning to the top, the navbar experiences glitches by hiding again. Attempting solutions from Bootstrap 4 S ...

Can anyone tell me where to find the unminified version of Bootstrap 3's docs.min.js file?

Could someone please provide me with the original version of this file? I've been trying to search for it in the project but haven't had any luck. You can find it here: https://github.com/twbs/bootstrap/blob/master/docs/assets/js/docs.min.js. ...

unable to toggle the navbar

Currently, I am facing an issue with the navbar-toggle button while using Bootstrap. Initially, I thought the problem was with my navbar code, so I tried pasting the example from the Bootstrap Website, but it did not work either. The button appears, but t ...

Error is thrown when attempting to access nested elements using GetElementsByClassName within the window.onload function

I have a funky looking table on my webpage, here's an example: <body> <table class="table table-bordered"> <thead> <tr> <th>#</th> <th>Product name</th> <th>Product ...

How to create custom options in a JavaScriptMVC Controller's event listener?

When working with JavascriptMVC's Controller, they have a unique format for handling events Rather than using traditional jQuery methods $(function(){ $('#tabs').click(someCallbackFunction1) $('#tabs .tab').click(someCallback ...

The hidden textbox loses its value when submitting

I have a form with fields and a RequiredFieldValidator. Additionally, I have another textbox that is hidden which gets populated by a JavaScript function: <script type="text/javascript"> $(document).ready(function (sender, args) { $("#myTextFiel ...

The AngularJS REST service fails to function properly when attempting to load page content through Ajax requests

My REST service retrieves data from the back end and displays notifications to the user when they click the notification button. Initially, the notification div is hidden, but when the button is clicked, it will display with the REST data. However, I have ...

Implementing event listeners with AngularJS after making a POST request

As I delve into the world of development, please forgive my lack of knowledge. My search for solutions brought me here. I am currently working on a comment and reply app. In order to add comments to my view, I am utilizing this specific function. $scope.i ...

Unraveling the Enigma of AJAX in Ruby

Greetings, experienced ones! Pardon my novice inquiry. I am currently endeavoring to associate a checkbox click in a "projects" display with a Javascript function that manipulates the data and subsequently transmits it via AJAX to the "complete" action of ...

I incorporated an AJAX-based page into the PrimeFaces tab, but unfortunately, it is not functioning correctly

I've added different pages within prime faces tabs and used ID-based forms on each page. However, when I enable AJAX for each page it doesn't work properly within the tab. Here is a snippet of my primary index.xhtml page: index.xhtml <?xml ...

Suggestions to update arbitrary content at a 5-second interval in Vue using Nuxt.js

As a Vue beginner, I am facing an issue with changing random text every 5 seconds while the page is loading. <template> <section class="container"> <h1 class="title"> Welcome {{ whois }} </h1> </section&g ...

What is the method for obtaining a dynamic route path within the pages directory in Next.js?

In my code, I have a special Layout component that compares routing queries and displays the appropriate layout based on the query. I'm looking to extend this functionality to handle dynamic routing scenarios, such as invoices/invoice-1. Currently, ...

Enhancing a Dropdown List with Jquery Using JSON Data

I am trying to populate a list using a JSON collection of objects. Here is the method that my action is returning: public ActionResult GetProductCategories() { var categories = _entities.ProductCategories.ToList(); var res ...

Modify the color of the components in Select from Material-UI

After reviewing numerous questions and answers on this topic, I have yet to find a suitable solution for my issue. Seeking guidance from the community for assistance. Utilizing the Select component from @mui/material to showcase the number of records per ...

Utilizing AngularJS to dynamically bind input to a value with a filter and keep it updated

I'm facing an issue with an input element linked to an object property along with a filter. Even though I update the object.field programmatically, the displayed value in the input does not change, although the correct value is reflected in the DOM In ...