Skip to navigation
Update and delete row for a jqgrid post request
16.06.21
1. Setting in the jqgrid: afterSetRow: async function(row){ let r = await update_row(row, url); log.info(r); }, afterDelRow: async function(id){ let r = await delete_row(id, url); log.info(r); }, 2. the handler function async function delete_row(_id, url) { url += "?_id=" + encodeURIComponent(unescape(_id)); let r = JSON.parse(await adelete_api(url)); } async function update_row(row, url) { let ret = ''; if(row.inputData.hasOwnProperty('id')) { let req = {"_id": 'id','_id_val':row.inputData['id'] }; for(let i in row.inputData) { req[i] =row.inputData[i]; } delete req['id']; delete req['oper']; ret = await post_json(url, JSON.stringify(req)); } return ret; } 3. the sending rest functions async function post_json(url,data) { return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); xhr.open("POST", url); xhr.setRequestHeader("Content-type", "application/json"); xhr.onload = () => resolve(xhr.responseText); xhr.onerror = () => reject(xhr.statusText); xhr.send(data); }); } async function adelete_api(url, json=false) { const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded"; return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); xhr.open("DELETE", url); xhr.setRequestHeader("Content-type", ctype); xhr.onload = () => resolve(xhr.responseText); xhr.onerror = () => reject(xhr.statusText); xhr.send(null); }); }
Reply
Anonymous
Information Epoch 1732546127
Design for the future, because it will be here sooner than you think.
Home
Notebook
Contact us