ser*_*lge 3 ajax asp.net-mvc asp.net-mvc-4
function girisAjaxKontrol() {
var kullanici = { 'kullaniciAdi': $('#username').val(), 'hidden': $('#password').val() };
$.ajax({
url: '/Giris/GirisGecerliMi',
type: 'POST',
data: kullanici,
success: girisAjaxReturn,
error: function (error, textstatus) {
JSON.stringify(error);
errorMessage($("div.girisSubmit input"), JSON.stringify(error), false);
}
});
Run Code Online (Sandbox Code Playgroud)
}
此函数会收到以下错误(它在部署之前正在运行).该网站是本地IIS 7.5上的Asp .Net MVC4网站; 我搜索了很多,但还没解决.
Server Error in Application \"DEFAULT WEB SITE\"
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
Requested URL http://localhost:80/Giris/GirisGecerliMi
Physical Path C:\\inetpub\\wwwroot\\Giris\\GirisGecerliMi
Logon Method Anonymous
Logon User Anonymous
Run Code Online (Sandbox Code Playgroud)
url: '/Giris/GirisGecerliMi',
Run Code Online (Sandbox Code Playgroud)
不应该像这样硬编码.您应该使用网址助手来生成此网址.原因是当您在IIS中部署应用程序时,您应该考虑一个虚拟目录名称,因此正确的URL是:
url: '/MyAppName/Giris/GirisGecerliMi',
Run Code Online (Sandbox Code Playgroud)
但是通过硬编码你的网址就没办法了.在ASP.NET MVC中,您应该始终使用url帮助程序Url.Action来生成给定控制器操作的URL,因为这些帮助程序不仅要考虑路由定义,还要考虑虚拟目录名称等内容.
所以正确的方法是让这个url生成服务器端并作为参数传递给girisAjaxKontrol函数:
function girisAjaxKontrol(url) {
var kullanici = { 'kullaniciAdi': $('#username').val(), 'hidden': $('#password').val() };
$.ajax({
url: url,
type: 'POST',
data: kullanici,
success: girisAjaxReturn,
error: function (error, textstatus) {
JSON.stringify(error);
errorMessage($("div.girisSubmit input"), JSON.stringify(error), false);
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3179 次 |
| 最近记录: |