开发者

jqGrid edit row with response 404 not found

开发者 https://www.devze.com 2023-02-21 01:02 出处:网络
I have started to use jqGrid in our project a few days ago and now I have a problem I can\'t solve. Below is my code:

I have started to use jqGrid in our project a few days ago and now I have a problem I can't solve. Below is my code:

var colModel = JSON.parse(gridResult.ColModel);

var grid = $("#tblGrid").jqGrid({
    url: './WebServices/Demand.asmx/GetDemandOpenHoursTwo',
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    serializeGridData: function (data) {
        return JSON.stringify(data);
    },
    datatype: 'json',
    mtype: 'POST',
    jsonReader: {
        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; }
    },
    height: 148,
    rowNum: 10,
    rowList: [10, 20, 30],
    colNames: gridResult.Columns,
    colModel: colModel,
    pager: "#gridPager",
    viewrecords: true,
    caption: "Öppetider",
    hidegrid: false,
    toolbar: [true, "top"],
    editurl: './WebServices/Demand.ascx/SaveDemandOpenHours',
    ajaxRowOptions: { contentType: 'application/json; charset=utf-8' },
    serializeRowData: function (data) {
        return JSON.stringify(data);
    }
});

And I have a button which calls the method saveRow:

toolbar.find('.te-save').click(function () {
    gr = grid.getGridParam('selrow');
    if (gr !== null) {
        grid.saveRow(gr, false);
    }
});

Everything works well with retrieving the data to the grid. But when I call saveRow I get a response with status 404 and message NOT FOUND. I tried to debug this and since the retrieving is working I changed the editurl to the exact same as the url. And then in the function serializeRowData I manipulate the data which will be 开发者_开发知识库posted and I replace it with the exact same data as the data posted to the web service method which retrieves data. With other words I am doing the exact same request when retrieving data as when I post an edited row. Hence the retrieving is working and the editing is not.

I inspected the requests in firebug and I can see that the requests are actually not the exact same. They differ in one parameter.

The request which is working has:

Accept: application/json, text/javascript, */*; q=0.01

And the request not working has:

Accept: */*

In every other way they are the same. Can this be the error? (It has to be this because one of them is working..).

Can anyone help me with the solution to my problem?


It seems to me that you have an typing error. You should use

editurl: './WebServices/Demand.asmx/SaveDemandOpenHours'

instead of

editurl: './WebServices/Demand.ascx/SaveDemandOpenHours'

The SaveDemandOpenHours return no data in case of successful saving, so the value of Accept header is not really important. If it is needed you can add dataType: 'json' in the ajaxRowOptions which you use.

0

精彩评论

暂无评论...
验证码 换一张
取 消