I\'m using jqGrid, latest version, and when I apply a edit rule that is a custom function and perform ajax it always returns \"Custom function should always return a arr
Your validateCar()
does not return anything because AJAX is asynchronous. And even if it was, you are returning something from a function assigned as a success
handler, not from the outer validateCar()
function.
When the response from your $.ajax
arrives, the method returned long ago. You either have to use synchronous AJAX (kind of discouraged):
validateCar: function (value, colname) {
var result = null;
jQuery.ajax({
async: false, //this is crucial
url: validateCarUrl,
data: { carName: value },
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data) {
result = [true, '']
} else {
result = [false, value + ' is not a valid car'];
}
},
error: function () { alert('Error trying to validate car ' + value); }
});
return result;
}
or redesign your function.