【问题标题】:Sending additional variable to server with dataUrl使用 dataUrl 向服务器发送附加变量
【发布时间】:2013-02-18 21:28:51
【问题描述】:

这应该是一个简单的修复,但我一直无法找到任何关于它的信息。

我同时使用 postData 和 editData 将变量 POST 到服务器以进行 表单编辑。此变量在开关中用于选择适当的功能。 此 php 包含项目的所有功能。我想避免有许多不同的 php 页面。

所以这一切都很好,但我找不到对 dataUrl 做同样事情的方法。我能够找到的一个线索是使用 ajaxSelectOptions,特别是数据选项。如果这是解决此问题的适当方法,那么使用它的方法是什么?像这样?:

ajaxSelectOptions:{
    contentType: "application/json",
    dataType:'json',
    type:'POST',
    action: function(){ 
        return 'popCodeAdjust';
    }
}

【问题讨论】:

    标签: php jqgrid


    【解决方案1】:

    一般您可以使用ajaxSelectOptionsdata 属性。代码凸轮看起来像

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

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

    herehere

    问题可能在于您确实需要以 JSON 格式发送数据。在这种情况下,您可能需要序列化参数数据的(如JSON.stringify({action: actionValue}))或带有参数名称的(如action: JSON.stringify(actionValue))。在WCF方法中查看the answer哪个角色扮演BodyStyle属性(WebMessageBodyStyle.WrappedWebMessageBodyStyle.WrappedResponse等)。

    在 jqGrid 4.4.2 或更高版本(参见the answermy pull requestthe fix)中,您可以使用postData 作为函数。你可以在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")});
        }
    }
    

    您可以在editoptions 内指定postData(请参阅here)。

    【讨论】:

    • 我很接近可以品尝到它,但没有雪茄。我只需要取出 contentType 和 dataType (json 格式不是必需的,就像我看到其他人所做的那样)。谢谢奥列格。
    【解决方案2】:

    怎么样?

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

    服务器端:

    $var = json_decode($_POST['varName'], true);
    

    【讨论】:

      【解决方案3】:

      在您的网格设置中,它将是:

      postData: { KeyName: KeyValue },
      

      你会看到这个额外的参数随着你的 POST 消失。

      下面的示例将设置 postData 值(如果要更改),然后触发重新加载网格。

      $('#gridName').jqGrid('setGridParam', { postData: { UserName: userName }).trigger('reloadGrid', [{ page: 1}]);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-21
        • 2014-03-01
        • 2013-03-10
        • 1970-01-01
        相关资源
        最近更新 更多