Sending additional variable to server with dataUrl

前端 未结 3 438
后悔当初
后悔当初 2020-12-12 07:15

This should be a simple fix, but I just have not been able to find anything about it.

I am using both postData and editData to POST a variable to the server for

相关标签:
3条回答
  • 2020-12-12 07:26

    How about?

    $.ajax({
        type: 'POST',
        url: 'url',
        data: { varName: JSON.stringify(arrayValues) },
        dataType: 'json',
        success: function(msg) {...},
        error: function(res, status, exeption) {...}
    });
    

    Server-side:

    $var = json_decode($_POST['varName'], true);
    
    0 讨论(0)
  • 2020-12-12 07:32

    Inside your grid setup it would be:

    postData: { KeyName: KeyValue },
    

    You will see this extra parameter go out with your POST.

    The example below will set the postData value, (if it was to change) and then trigger a reload of the grid.

    $('#gridName').jqGrid('setGridParam', { postData: { UserName: userName }).trigger('reloadGrid', [{ page: 1}]);
    
    0 讨论(0)
  • 2020-12-12 07:52

    In general you can use data property of ajaxSelectOptions. The code cam look like

    ajaxSelectOptions: {
        type: "POST",
        data: {
            action: "popCodeAdjust";
        }
    }
    

    or

    ajaxSelectOptions: {
        type: "POST",
        data: {
            action: function () {
                return "popCodeAdjust";
            }
        }
    }
    

    See here or here.

    The problem can be if you really need to send the data in JSON format. In the case you can need either to serialize the value of the parameter data (like JSON.stringify({action: actionValue})) or the value with parameter name (like action: JSON.stringify(actionValue)). See the answer which role play BodyStyle attribute (WebMessageBodyStyle.Wrapped, WebMessageBodyStyle.WrappedResponse etc) in WCF method in the case.

    In jqGrid 4.4.2 or higher (see the answer, my pull request and the fix) you can use postData as function. You can define it either inside of ajaxSelectOptions

    ajaxSelectOptions: {
        contentType: "application/json",
        dataType: "json",
        type: "POST",
        postData: function (rowid, value, name) {
            return JSON.stringify({action: "popCodeAdjust"});
            //or depend on the relinquishment of the server side
            //return {action: JSON.stringify("popCodeAdjust")});
        }
    }
    

    You can specify postData alternatively inside of editoptions (see here).

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