Dealing with jEditable response challenges

Having a collection of HTML, here is an example snippet:

<tr>
 <td>Name of Organisation:</td>
 <td class="edtext" id="organisation"><?=$aRes[0]['organisation']?></td>
</tr>

At the top of the page, this script is included:

$(function() {
    $(".edtext").editable("./editHandler/WRITE.update.php?uaID=<?=$uaID?>", {
        event       : 'dblclick',
        dataType    : "json",
        placeholder : '',
        indicator   : 'Saving...',
        cssclass    : 'editable',
        submit      : 'Save',
        cancel      : 'Cancel',
    });
});

By double clicking on the 'organisation' table cell, data can be edited and sent to the database successfully.

In the PHP backend, after updating the database, the following code is executed:

header('Content-type: application/json');

(snip database update code - it works fine)

$report = array();
$report['organisation'] = $userInput;
$report['result'] = "&#10004;";
echo json_encode($report);

The response sent back contains:

{"organisation":"Hello World","result":"&#10004;"}

However, the displayed content includes the tick symbol instead of the desired text. It's advised to show the text without quotes and have the result in a span or div with the id="result".

Integrating a jEditable callback option might be the solution, but examples are scarce. Assistance in implementing this efficiently would be greatly appreciated.

Furthermore, the requirement is to make this JavaScript work for multiple text fields without separate entries for each data cell that needs editing capabilities.

Answer №1

My solution to the issue involved including the following code snippet:

        callback    : function() {
            location.reload();
        },

within this block of code:

    $(".edtext").editable("./editHandler/WRITE.update.php?uaID=<?=$uaID?>", {
        event       : 'dblclick',
        dataType    : "json",
        placeholder : '',
        indicator   : 'Saving...',
        cssclass    : 'editable',
        submit      : 'Save',
        cancel      : 'Cancel',
    });
});

This adjustment ensured that the final code appeared as follows:

$(".edtext").editable("./editHandler/WRITE.<?=$appKey?>.php?uaID=<?=$uaID?>", {
    callback    : function() {
        location.reload();
    },
    event       : 'dblclick',
    placeholder : '',
    indicator   : 'Saving...',
    cssclass    : 'editable',
    submit      : 'Save',
    cancel      : 'Cancel',
});

The output mismatch was resolved by triggering a page refresh after a successful post, resulting in a clean appearance without unwanted elements.

While not an ideal workaround, it effectively addresses the issue without resorting to harmful hacks.

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

Custom Sign-in features in NextJS now direct users to the default form for entering login

I have been working on a web app that requires authentication using NextJS default auth middleware. However, whenever I try to log in, the app redirects me to the default NextJS form component at the URL /api/auth/signin?error=CredentialsSignin. Even thou ...

Methods to verify if an array contains a particular string within a PUG template

I'm currently working with NodeJS using Express and the PUG view engine. My goal is to determine whether an array includes a specific string. I've experimented with JavaScript's built-in methods like: array.includes(str) array.indexOf(str) ...

Is it possible for numerous identical components to trigger the display of the identical modal on a single webpage?

I am currently utilizing Vue in my project and I have a component that displays a button. When this button is clicked, it triggers a modal to open which is also part of the same component. The functionality works as intended. However, if there are multipl ...

The endpoint 'pusher/auth' returned a 404 error code indicating that it was

I'm currently setting up a private channel using Pusher on a local node.js server. Strangely, I'm encountering a 404 error with my auth endpoint. Initially, I suspected a problem with how I defined the endpoint in relation to the local server&ap ...

Can JavaScript's Gamepad API be used to register a custom game controller?

Background Story Working on a virtual reality app with A-frame to showcase VR gadgets. Custom controllers connect via websocket/bluetooth and we want them compatible with tracked-controls. These components use Gamepad API for model positioning and are fri ...

How to Redirect between Controllers in Nest.Js

I'm currently working with a module that looks like this: @Module({ imports: [], controllers: [AppController, AnotherController], providers: [], }) Within the AppController, I am attempting to implement res.redirect('/books') which r ...

Navigating horizontally to find a particular element

I developed a unique Angular component resembling a tree structure. The design includes multiple branches and nodes in alternating colors, with the selected node marked by a blue dot. https://i.stack.imgur.com/fChWu.png Key features to note: The tree&ap ...

Creating dynamic keys to insert objects

In my coding project, I am dealing with an empty array, a value, and an object. Since there are multiple objects involved, I want to organize them into categories. Here is an example of what I envision: ARRAY KEY OBJECT OBJECT KEY OBJECT ...

"Connecting a checkbox and radio button to a button for page navigation using JavaScript - a step-by-step guide

How can I link a checkbox and a radio button with a button to open a page using JavaScript? For instance: Select a checkbox and a radio button, then click a button to open a page. This concept caters to everyone: Select a checkbox and a radio button, then ...

navigating through elements and retrieving data from a decoded JSON structure

After successfully parsing with Newtonsoft, I am faced with the challenge of extracting every value associated with a key from the parsed string. Below is the JSON encoded string: {"result":[{"orderid":"94","imei":"clipper"},{"orderid":"93","item":"shoes ...

Issue with bootstrap 4 CDN not functioning on Windows 7 operating system

No matter what I do, the CDN for Bootstrap 4 just won't cooperate with Windows 7. Oddly enough, it works perfectly fine on Windows 8. Here is the CDN link that I'm using: <!doctype html> <html lang="en> <head> <!-- Req ...

Is it possible to trigger a JavaScript function by manipulating the URL of an HTML page?

Imagine this scenario: You have an HTML page located at example.com/test.html that contains several pre-defined JavaScript functions, including one named play(). How can I add JavaScript to the URL in order to automatically trigger the play() function wh ...

Is it necessary to reload the page each time to see updates on the navbar in nextjs?

I recently developed a Next.js application with a Navbar component integrated into my layout.tsx file. The challenge arises when a user logs in and is redirected to the home page, which showcases a link in the Navbar for viewing their profile. However, I n ...

Error: Unable to access the 'version' property of null

Having trouble installing any software on my computer, I've attempted various solutions suggested here but none have been successful. $ npm install axios npm ERR! Cannot read property '**version**' of null npm ERR! A complete log of this ru ...

Line numbers in Vue Codemirror

Currently, I'm working on integrating codemirror into my Vue.js application using a library found at https://github.com/surmon-china/vue-codemirror. The issue I'm facing is that even after importing and utilizing the codemirro component, everythi ...

Ensuring precise accuracy in JavaScript; transforming 0.5 into 0.5000

My current challenge involves converting every fraction number to n decimal places in JavaScript/Node.js. However, I've encountered a roadblock as it appears impossible to convert 0.5 to 0.5000. This discrepancy is causing my test cases that anticipat ...

Tips for finding information within a table using HTML

My task involves creating a table with the option for users to search data within it. However, I have encountered an issue where I am only able to search for data in the first row of the table. <table style="width:100%" id="table"> <tr> ...

Manipulate objects within an array by updating state with a button in React

So, I have an array of names that I want to cycle through: const data = { names: [ { name: "Jordan" // additional data }, { name: "Holly" // additional data }, { name: "Sean" // additional data ...

Navigating Parent Menus While Submenus are Expanded in React Using Material-UI

My React application includes a dynamic menu component created with Material-UI (@mui) that supports nested menus and submenus. I'm aiming to achieve a specific behavior where users can access other menus (such as parent menus) while keeping a submenu ...

Saving JSON data from Golang into a Postgresql database

I need to save a specific struct into my database that contains a JSON field. type Comp struct { CompId int64 `db:"comp_id" json:"comp_id"` StartDate time.Time `db:"start_date" json:"start_date"` EndDat ...