【问题标题】:jqGrid contentType header not getting setjqGrid contentType 标头未设置
【发布时间】:2014-01-21 18:38:08
【问题描述】:
   $("#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 可以正常工作。

更有趣的是loadBeforeSend(上图)能够添加contentType请求头。

在这种情况下,当 jqGrid 发出 HTTP 请求时,我希望能够将 application/json 添加为 contentType。

真的希望我忽略了一些东西。

【问题讨论】:

    标签: jquery ajax json iis jqgrid


    【解决方案1】:

    我有用于跨域请求的 jQuery.XDomainRequest 库,我必须删除它才能使其正常工作。 jqGrid 使用 contentType 请求标头。

    【讨论】:

      猜你喜欢
      • 2014-12-19
      • 2016-04-26
      • 2017-08-19
      • 2021-11-21
      • 2012-05-01
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多