Let's follow up this discussion at the Neptune Community

(this forum will be kept in read-only mode)
Implemented

additional data in callback handlers for ajaxSuccess and ajaxError

It is currently not possible to pass any additional data other than the ajaxid, however, it would be nice to do so. This data can later be used to evaluate the context from which the originating request was issued from. Currently, the getOnline... functions have the following form: function getOnlineMasterListCust(value) { $.ajax({ type: "POST", contentType: "application/json", url: "neptune_ajax?ajax_id=R_CUSTOMERS&ajax_applid=APP&sap-client=498&uxp=400&field_id=00198&ajax_value=" + value + "", dataType: "json", success: function (data) { modelMasterListCust.setData(JSONH.unpack(data.modelMasterListCustData)); setCacheMasterListCust(data.modelMasterListCustData); modelmt_off_customer_listings.setData(JSONH.unpack(data.modelmt_off_customer_listingsData)); setCachemt_off_customer_listings(data.modelmt_off_customer_listingsData); if (typeof(data.systemMessage) != "undefined"){alert(data.systemMessage.MESSAGE);} if (data.sysMessage){modelsysMessage.setData(data.sysMessage);} else {modelsysMessage.setData(data.customerMessage);} /* Client ajaxSuccess handler here */ } ,error: function (result, status) { /* Client ajaxError handler here */ } }); } To implement the requested feature it would be trivial to amend the function signature with an aditional data parameter which can be used in the callback body: function getOnlineMasterListCust(value, cbdata) { $.ajax({ type: "POST", contentType: "application/json", url: "neptune_ajax?ajax_id=R_CUSTOMERS&ajax_applid=APP&sap-client=498&uxp=400&field_id=00198&ajax_value=" + value + "", dataType: "json", success: function (data) { modelMasterListCust.setData(JSONH.unpack(data.modelMasterListCustData)); setCacheMasterListCust(data.modelMasterListCustData); modelmt_off_customer_listings.setData(JSONH.unpack(data.modelmt_off_customer_listingsData)); setCachemt_off_customer_listings(data.modelmt_off_customer_listingsData); if (typeof(data.systemMessage) != "undefined"){alert(data.systemMessage.MESSAGE);} if (data.sysMessage){modelsysMessage.setData(data.sysMessage);} else {modelsysMessage.setData(data.customerMessage);} /* Client ajaxSuccess handler here */ // cbdata can be accessed here! } ,error: function (result, status) { /* Client ajaxError handler here */ // cbdata can be accessed here! } }); } With the change, additional data can be passed in the second argument of getOnline... functions: getOnlineMasterList("ajax_id", {'foo': 'bar'}); Due to the nature of js argument handling, the proposed change is fully backwards compatible. `getOnlineMasterList("ajax_id");` is still a valid js function call.

1 person likes this idea
1 Comment

Hi Niklas,


thank you very much for your suggestion and becoming part of our community.  


There are currently easy ways to send additional data in your ajax calls (besides the ajax_id)


1- you already know the ajax_value string:      getOnlineMasterList( ajax_value


2- Send models:


image


image



In SP03 more flexibility is coming into the ajax calls.   In the getOnline..()  the  $.ajax (jqXHR) object will be returned so that more flexibility is provided for those who need it.


This way you will be able to call the 'getOnline' function as follows:

 

getOnlineMasterList('testValue').done(function(data) { console.log ('My custom success callback');});


Kind regards,

Julian





Login or Signup to post a comment