Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 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.

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';
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
347 views
Welcome To Ask or Share your Answers For Others

1 Answer

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...