I hope someone can help me with the following scenario because I'm breaking my small head over this! I have made a wrapper so I can easily call webservices/pagemethod using jquery. Now in the success function of the ajax call I want to be able to call a function (with optional parameters) I have done the following but I'm not sure if I'm the right direction:
function AjaxMethod(path, fn, paramArray, returnParamArray, successFn, errorFn) {
var paramList = '';
if (paramArray.length > 0) {
for (var i = 0; i < paramArray.length; i += 2) {
if (paramList.length > 0) paramList += ',';
paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
}
}
paramList = '{' + paramList + '}';
if (returnParamArray.length > 0) {
$.ajax({
type: "POST",
url: path + "/" + fn,
contentType: "application/json; charset=utf-8",
data: paramList,
dataType: "json",
success: function () {
var strFun = successFn;
var strParam = returnParamArray;
var funcCall = strFun + "('" + strParam + "');";
//Call custom function with parameter array
var ret = eval(funcCall);
},
error: errorFn
})
}
else {
$.ajax({
type: "POST",
url: path + "/" + fn,
contentType: "application/json; charset=utf-8",
data: paramList,
dataType: "json",
success: successFn,
error: errorFn
})
}
;}
I am able to call the function but I cant seem to pass the parameters. Am I going in the right direction or is this complete off the path ? Is it even possible to pass parameters/values as an array. Or is there an easier way to accomplish this.
By the way I need this function to make up the following (Schematic) actions:
1) User deletetes a row from a table with data - DeleteRow(rowindex)
2) DeleteRow calls the AjaxMethod to delete the row from database
3) On success event I want the specific row to be deleted visually, so I need the selected rowindex available in the successfunction. There are a couple of other scenarios too so it needs to be really dynamic.
I can also store this information in global vars like CurrentDeletedIndex but I hope it's possible in the way I was thinking.
I hope I made myself a little bit clear if not feel free to ask.
Thank you for your time.
Kind regards, Mark