POST Ajax call results in not found using jqGrid a

2019-01-28 23:57发布

问题:

This is puzzling me. I deployed an MVC 2 application to IIS6 and everything works fine except for my jqGrid calls to get data.

All is well on my development machine, but here are the two URLs I'm working with

Local dev web server:

POST http://localhost:port/Ctrl.mvc/JsonMethod

IIS6 (notice https - not sure if that matters)

POST https://www.domain.com/AppName/Ctrl.mvc/JsonMethod

The latter URL results in a HTTP 404, which is really confusing as all works well on my local machine. The JsonMethod is properly declared with [AcceptVerbs(HttpVerbs.Post)]

Let me know if any more info is needed - I appreciate any and all help with this!

EDIT Quite an oversight on my part..

All of my JSON requests are /Ctrl.mvc/JsonMethod. Well, on the IIS server, the code is in a sub-folder - AppName. As such, I'm getting a 404 because https://domain/Ctrl.mvc/JsonMethod is not found - which is correct.

Basically, I need to change my JSON requests when I deploy - which I really don't like, but perhaps there is a better way?

回答1:

Look at Deploy asp.net mvc beta to iis 6 causing 404's and http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/.

Do you have more URL in your application where POST are used? Are they work? Do you have more URLs without an extension like .aspx or .mvc? Are they work?

UPDATED: I had a problem with different base/root parts of my URL in all JavaScripts like you. Because you use jqGrid, I think you have the same problem. If I publish my solution in a virtual directory on a Web Server, then all URLs which call my JavaScripts will be changed. So I give window.location.pathname and split it with '/', then I find out a new rootPath corresponds to the new location. Such rebasing of URLs I placed in a function which I call inside of all JavaScripts of my solution. Hire is code fragment which works perfect on with my site:

var pathArray = window.location.pathname.split( '/' );
var rootPath = '';
for (var i = 0; i < pathArray.length; i++) {
    var p = pathArray[i];
    if (p === "") {
        continue;
    }

    if (p.toLowerCase() !== 'home') {
        rootPath += '/';
        rootPath += p;
    } else {
        break;
    }
}
this.urlBase = rootPath + '/Repository.svc';
this.urlExportBase = rootPath + '/ExportToExcel';

The solution is not perfect, but it works. It can be that you should change this "rebasing" function to make it working with your side.



回答2:

Use the mvc helpers to generate the url for the jqGrid ajax function to ensure the correct url is used.

$('#mygrid').jqGrid({ 
    url: '<%= Url.Action("MyControllerJsonAction", Model.RouteValues) %>' 
});


回答3:

When I use VS2012 release my project(MVC+Kendo UI) to IIS6.0 .The problem come out. F12 debug the error is 404,Chrome say the page can't find .

It's because the url is not right when you should add the Doamin in the url:

The right code is:

function QueryExpSendList() {
var EValid = true;
var uri = AJAXBaseUrl;
if (AJAXBaseUrl.indexOf("localhost") > 0) {
    uri = AJAXBaseUrl + "AJAX/QuerySendList/";
}
else {
    uri = AJAXBaseUrl + "KQExpress/AJAX/QuerySendList/";
}
GenerateExpressSendGrid(uri);
$("#QueryResult").show();

}

The Error Code:

function QueryExpSendList() {
var EValid = true;
var uri = AJAXBaseUrl + "AJAX/QuerySendList/";
GenerateExpressSendGrid(uri);
$("#QueryResult").show();

}

By sirili@163.com