2013-02-18 48 views
0

這應該是一個簡單的修復,但我只是一直無法找到任何有關它。發送附加變量到服務器與dataUrl

我正在使用postData和editData將一個變量發佈到服務器的表單編輯。該變量用於開關選擇適當的功能。 這個php包含了項目的所有功能。我想避免有許多不同的PHP頁面。

所以這一切都很好,但我無法找到一種方法來爲dataUrl做同樣的事情。我已經能夠找到的一個領導是使用ajaxSelectOptions,特別是數據選項。如果這是解決這個問題的恰當方法,那麼使用它的方式是什麼?像這樣?:

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

回答

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))的值序列化。參見the answer哪些角色扮演BodyStyle屬性(WebMessageBodyStyle.Wrapped,WebMessageBodyStyle.WrappedResponse等)在WCF方法中的情況。

在jqGrid 4.4.2或更高版本中(請參閱the answer,my pull requestthe fix),您可以使用postData作爲函數。您可以定義它作爲替換裏面的editoptionsajaxSelectOptions

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

您可以指定postData內(見here)。

+0

我已經足夠接近它的味道,但沒有雪茄。我只需要取出contentType和dataType(json格式不是一個必需品,正如我見過其他人所做的那樣)。感謝Oleg。 – user 2013-02-19 13:18:55

+0

@MattWall:不客氣! – Oleg 2013-02-19 13:28:17

0

怎麼樣?

$.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); 
0

內部網格的設置將是:

postData: { KeyName: KeyValue }, 

你會看到這個額外的參數,走出去與你的帖子。

下面的示例將設置postData值(如果要更改),然後觸發網格的重新加載。

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