Updating or inserting bulk data using an Ajax proxy with CRUD operations

While implementing a bulk update/insert feature using an ajax proxy, I ran into an issue with store.sync(). This method sends a request to the server for each dirty record. But if there is an error with any of the records on the server, how can I properly notify the client with a suitable message?

proxy: {
        type: 'ajax',
        url: "localhost:8888/service/baseLocations",
        reader: {
            type: 'json',
            rootProperty: 'data',
            successProperty: 'success',
            totalProperty : 'total'
        },
        actionMethods: {
            create: 'POST',
            read: 'GET',
            update: 'POST',
            destroy: 'DELETE'
        },
        writer : {
            type: 'json'
        },
        batchActions: false
}

Answer №1

When a store is updated using the sync method, there are three available options: onUpdateRecords, onDestroyRecords, and onCreateRecords. You can check the success property and use the rejectChanges method if needed.

For instance:


onUpdateRecords: function(records, operation, success) {
    if (!success){
         this.rejectChanges();
    }
}

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

When attempting to delete an item from Firebase using React, the re-render results in the item being

I'm currently in the process of developing an app to enhance my React skills, and I've chosen Firebase for data storage. Everything seems to be working fine as all items from Firebase are rendering properly. However, I've encountered an issu ...

Trouble encountered while using useRef in TypeScript

I'm encountering an issue with the code below; App.tsx export default function App() { const [canvasRef, canvasWidth, canvasHeight] = useCanvas(); return ( <div> <canvas ref={canvasRef} /> </div> ) ...

Nodemon fails to restart: [nodemon] attempting restart because of modifications

I ran the command: npm run server Despite my attempts to find a solution, I am still puzzled as to why the results are not working. Even after globally installing npm install -g nodemon, the server still does not restart automatically and only displays me ...

Storing map tiles offline in React-Leaflet

One common method I have come across for storing tiles offline with Leaflet involves using localforage. Here's an example: const map = L.map("map-id"); const offlineLayer = L.tileLayer.offline('https://server.arcgisonline.com/ArcGIS/res ...

Tips for resolving the 'route.search' bug in Express.js

I recently started working on a basic Express app (with Node) and I am in the initial setup phase. However, I have encountered an error that is proving to be quite challenging to resolve. Despite my attempts to search for solutions online and browse throu ...

strange occurrences in localToWorld transformation

Hello there! Currently, I'm working on a project where I'm generating a TextMesh using font geometry and placing it within an empty pivot object. My goal is to obtain the world coordinates of each vertex in the TextMesh so that I can manipulate ...

Unable to retrieve Dictionary(Of String, String) using a GET ajax web request, but it functions properly with a POST request

This is the web method I have implemented: <WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True, XmlSerializeString:=True)> _ Public Function GetDictionary() As Dictionary(Of String, String) ...

Blending synchronous and asynchronous testing with Mocha

There is a function that calculates certain values and informs the user about events using callbacks: function returnAndCallback(callback) { callback(5); // not always called return 3; } Incorporating Mocha and Should.js, a test was created: descri ...

Implementing a Masonry layout within an ASP UpdatePanel

I have an ASP-WebPage where I'm using an UpdatePanel with a Dropdown and Output-Div for dynamically generated Cards. These cards are layouted by Masonry. The content of the Output-Div is bound to the Dropdown selection. Initially, the Masonry-Layout ...

Is there a way to automatically hide divs with the style "visibility:hidden" if they are not visible within the viewport?

Currently, I am working on developing a mobile web app. Unfortunately, Safari in iOS 5.1 or earlier has limited memory capabilities. In order to reduce memory usage while using css3 transitions, I have discovered that utilizing the css styles "display:none ...

Building XML using PHP with relatively extensive information stored in JavaScript

Similar Question: XML <-> JSON conversion in Javascript I have a substantial amount of data stored in JavaScript that I need to convert into an XML file on the PHP server. The process of transforming the data into a JSON object, sending it to PH ...

Resolve the issue pertaining to the x-axis in D3 JS and enhance the y-axis and x-axis by implementing dashed lines

Can anyone assist with implementing the following features in D3 JS? I need to fix the x-axis position so that it doesn't scroll. The values on the x-axis are currently displayed as numbers (-2.5, -2.0, etc.), but I want them to be shown as percentag ...

Making sure the axios API call is completed before rendering the child component with props

Check out the snippet of code I've provided: function StoryCarousel(props) { const [ivrDests, setIVRDests] = useState([]); useEffect(() => { async function getIVRDests() { var data = { "customer-id": ...

I'm having trouble getting my .click method to work with the <div id=menuButton>. Can anyone help me figure out why this is happening?

Here is the HTML code I created for a dropdown menu. Initially, in the CSS file, the menu is set to display: none; <!doctype html> <html> <head> <title>DropDown Menu</title> <link rel="stylesheet" href="normalize ...

What is the best way to change an int32 to a float32 in Deeplearn.js?

In December 2017, this code did the job perfectly. However, after updating Deeplearn.js to the latest version, it no longer functions as expected: math.scope(function(keep, track) { var i = track(dl.Array3D.fromPixels(rawImageData, 4)); i = math.multi ...

Guide on transferring value from a <select> element using JavaScript

I'm attempting to pass the selected value of a <select> in the onChange function. I've explored this question on SO, but unfortunately, using this and this.value hasn't been successful. I understand that the question is quite old... se ...

Is there a way to sort data by year and month in mongodb?

I'm trying to filter data by year in MongoDB based on a specific year and month. For example, if I pass in the year 2022, I only want to see data from that year. However, when I try using the $gte and $lte tags, it returns empty results. Can someone g ...

JavaScript - rearrange array of objects based on specified property

I am currently designing a select dropdown input element for a webpage and I want to create a specific 'popular' options group that will be displayed at the top of the dropdown menu. The data structure I am working with is as follows. I am tryi ...

The file object appears to be empty when attempting to send it to the server using ng

Using ng-file-upload, I am attempting to upload a single file to my server. After selecting the file and passing the file object ($scope.myFiles[0]) to my angular service, I noticed that when inspecting the HTTP request in the developer tools, the file ob ...

Audio playback is being disrupted by simultaneous ajax requests

Whenever my chatbot responds, I want to play an audio file. I have set up an API where the audio file is stored and called using AJAX on each response. It works fine with a single response, but when there are multiple responses, the audio gets overlapped - ...