Receiving feedback from an asynchronous request

Before diving in, I dedicated a significant amount of time to exploring this insightful discussion: How can I fetch the response from an asynchronous call?

Within my code, there's a static variable named "d" which is essentially a 2-dimensional array:

var d = [
    ["05_001","05_002","05_003","05_004","05_005"],
    ["05_006","05_007","05_008","05_009","05_010"]
];

The goal here is to leverage AJAX to pull data from a database instead.

An attempt was made using this approach:

function foo(callback) {
    return $.ajax({
        url: 'emoji.php?cat=emoticons_activity',
        success: callback
    });
}

var result;
foo(function(response) {
    result = response;
    alert(result);
});

However, even with that workaround, a roadblock emerges as it's imperative to assign the value returned by the "foo" function to the variable "d".

This puzzle needs to be solved within the context of another block of code:

tinymce.PluginManager.add("emoticons_travel_places", function(a, b) {
    function c() {
        var a;
        return a = '<table role="list" class="mce-grid">', tinymce.each(d, function(c) {
            a += "<tr>", tinymce.each(c, function(c) {
                var d = b + "/img/" + c + ".svg";
                a += '<td><a href="#" data-mce-url="' + d + '" data-mce-alt="' + c + '" tabindex="-1" role="option" aria-label="' + c + '"><img src="' + d + '" style="width:30px; height:30px" role="presentation" /></a></td>'
            }), a += "</tr>"
        }), a += "</table>"
    }

    var d = [
        ["05_001","05_002","05_003","05_004","05_005","05_006","05_007","05_008","05_009","05_010","05_011","05_012","05_013","05_014","05_015","05_016","05_017","05_018","05_019","05_020"],
        ["05_021","05_022","05_023","05_024","05_025","05_026","05_027","05_028","05_029","05_030","05_031","05_032","05_033","05_034","05_035","05_036","05_037","05_038","05_039","05_040"],
        ["05_041","05_042","05_043","05_044","05_045","05_046","05_047","05_048","05_049","05_050","05_051","05_052","05_053","05_054","05_055","05_056","05_057","05_058","05_059","05_060"],
        ["05_061","05_062","05_063","05_064","05_065","05_066","05_067","05_068","05_069","05_070","05_071","05_072","05_073","05_074","05_075","05_076","05_077","05_078","05_079","05_080"],
        ["05_081","05_082","05_083","05_084","05_085","05_086","05_087","05_088","05_089","05_090","05_091","05_092","05_093","05_094","05_095","05_096","05_097","05_098","05_099","05_100"],
        ["05_101","05_102","05_103","05_104","05_105","05_106","05_107","05_108","05_109","05_110","05_111","05_112","05_113","05_114","05_115"]
    ];

    a.addButton("emoticons_travel_places", {
        type: "panelbutton",
        panel: {
            role: "application",
            autohide: !0,
            html: c,
            onclick: function(b) {
                var c = a.dom.getParent(b.target, "a");
                c && (a.insertContent('<img src="' + c.getAttribute("data-mce-url") + '" width="30" height="30" alt="' + c.getAttribute("data-mce-alt") + '" />'), this.hide())
            }
        },
        tooltip: "Emoticons - Travel & Places"
    })
});

The objective is to replace the existing var d = ... part with the output of the AJAX request.

Rewriting the entire block isn't viable due to its integration into the TinyMCE plugin system.

Progress feels within reach, yet challenges persist after days of intermittent troubleshooting efforts.

Answer №1

In the end, I was able to find a solution by using TinyMCE's built-in tinymce.util.XHR.send method:

tinymce.util.XHR.send({
    url: 'emoji.php?cat=emoticons_travel_places',
    success: function(returnedData) {
        MyData = JSON.parse(returnedData);
        d = MyData;
       }
});

This answer can be found here:

tinymce.util.XHR.send -> variable

For more information, refer to the TinyMCE documentation on tinymce.util.XHR.send

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

Searching for an item in an array within MongoDB: Tips and techniques

I am attempting to locate the object containing a specific element within an array: Here is my query: router.get('/', function(req, res) { var userSubscribed = req.user.email; db.posts.find({ "SubscriberList": { $elemMatch: userSubscrib ...

"Utilize Node.js to generate a nested array structure with groupings

Here is an array data that I have: [ { tempId: 1, nik: '11002', employeeName: 'Selly Amaliatama', basic_salary: 3500000, id_component: 'AD0128114156', componentName: 'Tunjangan Maka ...

Resizable <textarea> with unique geometries

Is there a way to create a design for a textarea in the shape of a speech bubble or thought bubble, similar to what you might see in a comic? Ideally, I would like it to expand as text is entered into it. UPDATE: Hello everyone! Apologies for the earlier ...

Ensure that the view remains consistent while navigating a table that contains expanding concealed information

My table is dynamically populated with data within a div that has overflow: scroll and height set properties. The issue I face is that the data populates from the top, making it difficult to keep track of specific rows when scrolling within the #container ...

Display the QWebEngineView page only after the completion of a JavaScript script

I am currently in the process of developing a C++ Qt application that includes a web view functionality. My goal is to display a webpage (which I do not have control over and cannot modify) to the user only after running some JavaScript code on it. Despit ...

File Upload Manager (Using Ajax in Asp.net 4.0)

I'm currently working on a website using asp.net. I have implemented 5 Ajax File Upload controls on a page, but I am struggling to retrieve the "filename" of the uploaded file for each control. Can anyone provide assistance with this issue? Thank you ...

Inject arguments/data into the methods to showcase the name within a newly instantiated component in VueJS

I implemented a feature that allows collapsing sections within a table body. There is an "add" button represented by the "+" sign, and when clicked, it adds a new collapse section with content. I want to display the name of the data row (e.g., "iPhone") wh ...

What is the best way to retrieve the most recent CSV file in an Ajax request?

Below is the workflow I am currently dealing with: 1) The client makes an AJAX call on index.html to select a dataset 2) processor.php generates a new CSV file based on the data obtained from a MySQL query 3) Upon callback in index.html, d3.js uses the d ...

Leveraging React libraries within Astro

Recently, I decided to create my own portfolio site and I opted for Astro as my platform of choice. While Gatsby was a consideration, Astro stood out to me as a more high-performing solution with greater flexibility (especially since it's not tied to ...

Error in Node.js: Unable to access properties of null value within Express

While using Express (with node.js) and MongoDB, I encountered an error when trying to view or update a user profile. The middleware token check worked fine getProfileFields:::::::::::::>>>>e: TypeError: Cannot read properties of null (rea ...

Unveiling the Truth about Svelte Transitions

Recently, I attempted to incorporate the guidance provided in this repl () for implementing flying and fading effects on divs. However, it seems that I may have a slight misunderstanding regarding the concept... To tackle this, I designed a component rese ...

Navigating to a specific div on page load with pjax enabled

Utilizing pjax, when a user clicks a link the content is dragged in instead of loading a new page. The content includes a navigation bar at the top with the rest of the content underneath. When clicking on the navigation bar, it hides and displays certain ...

Semantic UI form validation is initiated by clicking any button

Within my Semantic UI form (<div class="ui form">), it seems that every button is triggering the form validation, even if it's not a submit button. I have two different types of buttons below: <button class="ui blue right labeled icon prima ...

Ways to retrieve the specified data in Javascript in string format

I'm facing an issue where the data I passed from a JavaScript array to a Java servlet and back to JavaScript is showing as "undefined." Check out my JavaScript code below: var buildingNumbers = []; // Let's assume the values of buildingNumbers ...

Present location of current page

I utilize angularJS to create a web page with the utilization of ngView for a single page and multiview. Is there a way to display the current page's location, such as Home/abc/dcv? On this website https://docs.angularjs.org/guide/, the page location ...

What is causing the conversion of integers to strings when I make a POST request using jquery.ajax to a PHP script

I've been struggling for the past hour trying to solve this issue with no success. Despite reading numerous posts on Stack Overflow related to jQuery and ajax(), I haven't found a solution that addresses my specific problem. Here is an overview ...

Custom options titled MUI Palette - The property 'primary' is not found in the 'TypeBackground' type

I am currently working on expanding the MUI palette to include my own custom properties. Here is the code I have been using: declare module '@mui/material/styles' { interface Palette { border: Palette['primary'] background: Pa ...

What is the best way to make changes to the DOM when the state undergoes a

I've programmed the box container to adjust dynamically based on input changes. For instance, if I entered 1, it will generate one box. However, if I modify the input to 2, it mistakenly creates 3 boxes instead of just 2. import React from 'rea ...

Exporting Colada textures for use in Three.js

I have some files in .FBX format that need to be converted to Collada so I can use them in Three.js. While I was able to convert them using FBX Converter, I discovered that the textures were lost in the process. How can I convert these files while retainin ...

Personalizing Google Map pin

I found some code on Codepen to add pointers to a Google map. Currently, it's using default markers but I want to change them to my own. However, I'm not sure where in the code to make this update. Any examples or guidance would be appreciated. ...