jqGrid custom edit rule function using Ajax displays “Custom Function should return array!”

后端 未结 1 1835
我寻月下人不归
我寻月下人不归 2021-01-28 06:08

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

相关标签:
1条回答
  • 2021-01-28 06:10

    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.

    0 讨论(0)
提交回复
热议问题