使用 dataUrl 向服务器发送附加变量 [英] Sending additional variable to server with dataUrl

查看:18
本文介绍了使用 dataUrl 向服务器发送附加变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I am using both postData and editData to POST a variable to the server for form editing. This variable is used in a switch to select the appropriate function. This php contains ALL of the functions for the project. I want to avoid having many different php pages.

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

So all of that is fine, but I cannot find a way to do the same thing for dataUrl. The one lead I've been able to find is using ajaxSelectOptions, specifically the data option. If this is the appropriate way to go about this, what is the way to use it? Like this?:

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

推荐答案

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

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

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

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

请参阅此处这里.

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

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.

在 jqGrid 4.4.2 或更高版本中(参见答案我的拉取请求修复) 你可以使用 postData 作为函数.您可以在 ajaxSelectOptions

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")});
    }
}

您也可以在 editoptions 内指定 postData(请参阅 这里).

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

这篇关于使用 dataUrl 向服务器发送附加变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆