This POSTed request was attempted without a valid authenticity token.
/* file: getDbItemViaAjax.js */
// GET the EVENT record(s) from the Database
function getDb_CurEvents() {
var params = { format:'json', inventoryitemid:g.curItemNum };
var paramsStr = jQuery.param( params );
$.ajax({
url: (g.api_url+'/inventoryevents/?'+ paramsStr )
,
type: "GET",
dataType: "json",
contentType: 'application/json',
cache:false,
timeout: 20000,
success: function( rsp ) {
// IN FETCHING__Db_CUR_EVENT__STATE
manageStatesAndTransitions(
"json_rsp_db__CUR_EVENTS" /* "event.type" */
, rsp
);
},
error: function( xmlhttprequest, textStatusStr, errorThrownStr ) {
if(textStatusStr=="timeout") {
alert("ERROR~286: getDb_CurEvents() timed out");
} else {
alert( "Error~300: getDb_CurEvents() ${xmlhttprequest} textStatus=" + textStatusStr + " errorThrown=" + errorThrownStr);
if (xmlhttprequest.responseText) {
var subStr = xmlhttprequest.responseText.match("(\<\/header\>)(.*)(\<\/body\>)");
if (subStr !== null) {
alert(subStr[1]);
alert(subStr[2]);
// see https://www.tutorialrepublic.com/faq/how-to-find-substring-between-the-two-words-using-jquery.php
} else {
alert(xmlhttprequest.responseText);
}
}
}
}
});
}
/* inventoryevents CONTROLLER */
/**
* View all [modelNames]
*
* AJAX CALL: http://www.gleneckguideto.com/aod_inv/inventoryevents/?format=json&inventoryitemid=1
*/
function index() {
LOCAL.mp= pluralize(this.modelName);
if(structKeyExists(params, "format") AND (params.format=="json")) {
/*
* $AJAX GET: "http://www.gleneckguideto.com/aod_inv/inventoryevents/?format=json&inventoryitemid=1&_=1595128550429?"
*/
LOCAL.AjaxResponse = GetNewAjaxResponse();
if(structKeyExists(params, "inventoryitemid")) {
// ORIGINAL CODE
LOCAL.inventoryevent= model("inventoryevent").findAllByInventoryitemid(
value=params.inventoryitemid
, order = "asofdate,id"
, returnAs="structs"
);
// LOCAL.AjaxResponse.token = "";
LOCAL.AjaxResponse.data= SerializeJSON(LOCAL.inventoryevent);
} else {
LOCAL.AjaxResponse.success= false;
ArrayAppend(LOCAL.AjaxResponse.errors, LOCAL.modelName & ' ' & "no inventoryeventid specified" );
}
renderWith( data=LOCAL.AjaxResponse , hideDebugInformation=true);
} else {
param name="params.page" type="integer" default="1";
/* params.orderby="upcid ASC"; */
params.orderby="id DESC";
scaffold("index", gtableDescription);
}
}
public struct function GetNewAjaxResponse( ) {
// Define the local scope.
var LOCAL = {};
// Create new API response
LOCAL.AjaxResponse = {};
LOCAL.AjaxResponse["success"] = true;
LOCAL.AjaxResponse["errors"] = [];
LOCAL.AjaxResponse["data"] = "";
LOCAL.AjaxResponse["token"] = "";
// Return the empty AjaxResponse object
return (LOCAL.AjaxResponse);
}
function post_DbEvent_Update(dbEvent_id, iNewCount, iNewTotalValue) {
var params = { format:'json', id:dbEvent_id, itemcount:iNewCount, totalvalue: iNewTotalValue};
var paramsStr = jQuery.param( params );
alert(g.api_url+'/inventoryevents/' + dbEvent_id + '?'+ paramsStr );
$.ajax({
url: (g.api_url+'/inventoryevents/' + dbEvent_id + '?'+ paramsStr ) ,
type: "PUT",
dataType: "json",
contentType: 'application/json',
cache:false,
data: { id:dbEvent_id }
timeout: 15000,
success: function( rsp ) {
alert( "post_DbEvent_Update() rsp is " + rsp );
manageStatesAndTransitions(
"json_rsp_db__ITEM" /* "event.type" */
, rsp
);
},
error: function( xmlhttprequest, textStatusStr, errorThrownStr ) {
if(textStatusStr=="timeout") {
alert("ERROR~723: getNext_DbItem() timed out");
} else {
alert( "Error~726 ${xmlhttprequest} textStatus=" + textStatusStr + " errorThrown=" + errorThrownStr);
}
}
});
} /** * Update [inventoryevents] **/
function update()
{
LOCAL.mp =pluralize(this.modelName);
if (structKeyExists(params, "format") AND(params.format == "json"))
{
LOCAL.AjaxResponse = GetNewAjaxResponse();
if (structKeyExists(params, "totalvalue"))
{
if(structkeyexists(params, local.modelName)){
variables[local.modelName]=variables.model(local.modelName).findOneById(
value=param.key);
variables[local.modelName].update(params[local.modelName]);
if ( variables[local.modelName].save() ) {
redirectTo(route=local.mp, success=l(local.modelName) & ' ' & l("successfully updated"));
}
else {
renderView(action="edit", error=l("There were problems updating that") & ' ' & l(local.modelName));
}
}
LOCAL.AjaxResponse.data = SerializeJSON(LOCAL.inventoryevent);
} // of structKeyExists(..."totalvalue"))
else { // NORMAL: return HTML page
scaffold("update", gtableDescription);
}
} // of json
}