2014-01-21 63 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请求头。