2014-01-21 59 views
0
$("#liveRTMessages").jqGrid({ 
    url: $RT.ENDPOINT, 
    datatype: "json", 
    postData: { 'system': null }, 
    mtype: "POST", 
    height: "100%", 
    colNames: $RT.colNames, 
    colModel: $RT.MessageModel, 
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
    gridview: true, 
    loadBeforeSend: function (xhr) { 


// for testing only 
     $.ajax({ 
      type: "POST", 
      url: $RT.ENDPOINT, 
      data: {}, 
      datatype: "json", 
      contentType: 'application/json; charset=utf8', 
      success: function (data) { 
       var t = data; 
      } 
     }); 
    }, 
    serializeGridData: function (postData) { 
     if (postData.searchField === undefined) postData.searchField = null; 
     if (postData.searchString === undefined) postData.searchString = null; 
     if (postData.searchOper === undefined) postData.searchOper = null; 
     //if (postData.filters === undefined) postData.filters = null; 
     return JSON.stringify(postData); 
    }, 
    jsonReader: { 
     repeatitems: false, 
     root: function (obj) { return obj.d.rows; }, 
     page: function (obj) { return obj.d.page; }, 
     total: function (obj) { return obj.d.total; }, 
     records: function (obj) { return obj.d.records; } 
    }, 
    loadComplete: function (data) { 
     // future event handling, very last grid event thrown 
    }, 
    loadError: function (xhr, status, error) { 
     return; 
    } 
}); 

我得到jqGrid正常工作的GET請求。但POST失敗,因爲我無法在http請求上設置contentType。 IIS期望'application/json'作爲contentType的請求。這工作正常使用$ .ajax。jqGrid contentType標題未設置

更有趣的是,loadBeforeSend(上面)能夠添加contentType請求標頭。

當jqGrid在這種情況下發出HTTP請求時,我希望能夠將application/json添加爲contentType。

真的希望有一些我忽視的東西。

回答

0

我有jQuery.XDomainRequest庫的跨域請求,我不得不刪除,以得到這個工作。 jqGrid使用contentType請求頭。