Mockjax causes interference with X-editable's AJAX update functionality

$(function(){



            //enable / disable
            $('#enable').click(function() {
                $('#user .editable').editable('http://domain.com/update.php');
            });    

            //modify buttons style
            $.fn.editableform.buttons = 
            '<button type="submit" class="btn btn-success editable-submit btn-mini"><i class="icon-ok icon-white"></i></button>' +
            '<button type="button" class="btn editable-cancel btn-mini"><i class="icon-remove"></i></button>';  

            //editables 
            $('.remarks').editable({
                url: 'http://domain.com/update.php',
                display: function(value, response) {
                //render response into element
                $(this).html(response);
                }
            });



            
        });

When using Mockjax, the HTML element on the page gets updated but the MySQL row is not. On the other hand, without Mockjaz, the MySQL row update works but the HTML element remains unchanged.

Is there a workaround to make both the MySQL row and the HTML element update simultaneously?

Your help is greatly appreciated. Thank you!

Answer №1

I see mockjax being used in this code snippet, but isn't it typically utilized for mocking purposes only? Shouldn't ajax be the preferred method instead? Here's how you could incorporate ajax:

 $('#a').editable({
    validate: function(value) {
        if($.trim(value) == '') return 'This value is required.';
    },
    type: 'text',
    url: '/post',
    pk: '123', // id of the row in your db...
    title: 'Enter Value',
    params: function(params) {
        var data = {};
        data['id'] = line;
        data['field'] = params.name;
        data['value'] = params.value;
        return data;
    },
    ajaxOptions: {
        dataType: 'json'
    },
    display: function(value, response) {
        $(this).text(response.new_value_from_server);
    },
    success: function(response, newValue) {
        // Output any desired message upon successful submission
    }
});     

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

A login page designed with jquery does not require resubmission

Encountering an issue where after submitting incorrect login credentials on a webpage, the ajax request fails to go through upon subsequent attempts. After scouring StackExchange for solutions, I have explored threads such as Why won't my jQuery form ...

What is the best way to compare an escaped field in PHP/MySQL?

I'm facing a challenge where I am unsure why certain values are automatically escaping when inserting into MySQL using Doctrine. For instance, if a user inputs he/she, it gets stored as he\/she in the database table. This causes problems when us ...

How to Invoke JavaScript Functions within jQuery Functions?

I'm working on a jQuery function that involves dynamically loading images and checking their width. I have two JavaScript functions, func1() and func2(), that I want to call from within the jQuery function in order to check the width of each image. T ...

Boost the frequency of AJAX requests made by a website

I am looking to optimize the number of ajax calls my website is making to my Java Servlets server. My idea is to have a single request sent to a MainServlet, which will then handle sending multiple requests to OtherServlets. Rather than having the respon ...

What is the purpose of implementing asynchronous loading for JavaScript in my webpack setup?

I am facing difficulties with handling unusual codes. I am trying to add some query parameters using $.ajaxPrefilter in all jQuery ajax requests. I came across the following code snippet which seems to ensure synchronous loading order, but in my entry.js ...

Exploring Ancestors with Jquery to Find Input Fields

In my current project, I am working on a function that needs to extract the values from two input fields within a specific div element. These values will then be added to an array and posted as JSON data. However, I am facing difficulties in navigating thr ...

What steps can I take to create efficient live forms using AJAX and jQuery only?

I've been attempting to create AJAX forms but have had no success so far. I experimented with iframes, but found them to be not as effective. However, these are the only methods I have tried and am familiar with. Although I attempted to use the $.AJA ...

`Trigger a page reload when redirecting`

Currently, I am tackling some bug fixes on an older Zend Framework 1.10 project and encountering difficulties with redirection and page refresh. The issue: The task at hand is to make an AJAX call, verify if a person has insurance assigned, and prevent de ...

How can I use jQuery to show the text value of a selected checkbox, dropdown menu, and flipswitch in a popup?

This form's HTML is set up for input with a popup display feature upon submission. Currently, only text can be displayed in the popup. It doesn't show the text of selected checkboxes or dropdown lists - just numbers for the dropdown and "ON" for ...

Ways to turn off .removeClass()

Encountering an issue with jquery-2.1.4.js. Upon integrating a layerslider into my website, the script modified div classes. Attempted using older versions of the script without success. Currently have classes as follows: <a href="#" class="col-md-3 ...

Using jQuery to validate the existence of a link

Within my pagination div, I have links to the previous page and next page. The link to the previous page is structured as follows: <span id="previous"><a href="www.site.com/page/1" >Previous</a>. However, on the first page, there will be ...

Utilizing PHP and AJAX for an Innovative Login System

I am facing an issue with my sign in form implementation using ajax, jquery, and PHP. The problem I am encountering is that the $result variable always returns false. As a beginner in this field, I hope to receive assistance from all of you. Below is the ...

Displaying group field data in one page on JQGrid when pagination is enabled

Is there a way in JQGrid to display group data on one page? Specifically, if displaying all items from an order would exceed the list limit, I want to only show data up to the previous order without exceeding the limit. How can this be achieved? ...

What is the best way to halt an asynchronous method as a user?

How can I implement a mechanism that allows a user to stop an async method in MVC? My idea for implementation is as follows: public string stopToken { get; set; } public int iteration { get; set; } public async Task<string> someActionAsync() { ...

Ways to prevent the jQuery simple slider from transitioning slides while it is in an invisible state

There is a jQuery slider on my website that behaves strangely when I navigate away from the Chrome browser and return later. It seems to speed through all pending slides quickly when it was not visible. Now, I want the slider to pause when it becomes invi ...

Anticipate the arrival of the getJSON response

Currently, I am working on a script that utilizes Yahoo's YQL within a web application. This script is designed to scan through a text paragraph, identify references, and display them as popups within the text. Everything works smoothly until I reach ...

Is it feasible to make Twitter's Typeahead plugin have an initial slide down or fade in effect?

Does anyone have an easy way to make the dropdown from Twitter's typeahead jQuery plugin initially slide down or fade in? I'm trying to animate the size of the dropdown menu when it adjusts, but even a simple fade or slide in would be fine. I pre ...

Extract the URL's name using jQuery

Looking for a way to extract the "step2" value from a given URL? Here's a JavaScript solution: const url = window.location.href; console.log(url); For example, let's consider this URL: http://www.myproject.com/wp/?edit_project=797#step2=projec ...

Choosing children in jQuery can be tricky, especially when you want to avoid selecting the root element with the same name

I am encountering a challenge with my XML structure where some child elements share the same name as the root element. I am seeking a way to specifically select these child elements without including the root element itself. Despite searching through the j ...

PHP script encountering a 404 error during execution (Approximately 45 seconds in)

I have a script located in a directory that does not have any set execution time limits (I routinely run scripts lasting hours from this location) along with a file within it. This file is called from an HTML form on a CodeIgniter view, which uploads a CSV ...