使用dataUrl将其他变量发送到服务器 [英] Sending additional variable to server with dataUrl

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

问题描述

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

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

我同时使用postData和editData将变量发布到服务器以进行表单编辑.此变量用于开关中以选择适当的功能. 此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,特别是data选项.如果这是解决此问题的适当方法,那么使用它的方式是什么?这样吗?:

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格式发送数据.在这种情况下,您可能需要序列化参数数据的(例如JSON.stringify({action: actionValue}))或带有参数名称的值(例如action: JSON.stringify(actionValue)).在这种情况下,请参见答案,在WCF方法中哪个角色扮演BodyStyle属性(WebMessageBodyStyle.WrappedWebMessageBodyStyle.WrappedResponse等)

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或更高版本中(请参见答案

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天全站免登陆