为什么 Ajax 脚本没有在 IIS 7.5 Win 2008 R2 服务器上运行? [英] Why the Ajax script is not running on IIS 7.5 Win 2008 R2 server?

查看:35
本文介绍了为什么 Ajax 脚本没有在 IIS 7.5 Win 2008 R2 服务器上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Web 应用程序可以在我的开发服务器上的 VS 2013 上正常运行,但是一旦我将它发布到 IIS 7.5 2008 R2 服务器上,位于我的自定义脚本文件中的 Ajax 脚本就不再工作了,尽管其他不调用 Ajax 的 JQuery 脚本可以正常工作.为了让ajax在服务器中工作,还有什么需要做的吗?我已经阅读了一些关于的帖子,但还没有找到答案.我在 IIS 和 Ajax 方面的经验有限.

//更新:

我已经发现 Ajax 脚本可以工作并且问题很可能出在以下行中:

"url: '/Home/GetRates',//请求的 URL"

使用调试器我发现在远程服务器中没有调用 GetRates() 函数,尽管它在本地(在 VS 2013 下)开发服务器中.我看到的唯一区别是路径,但不知道如何修复它.下面是 Ajax 脚本:

//检索汇率并更新局部视图$(函数(){$('#reservSearch').submit(function () {如果 ($(this).valid()) {$("#theModal").modal("show");//显示进行中.....$.ajax({url: '/Home/GetRates',//请求的 URLdata: $("#reservSearch").serialize(),//要发送的数据(将转换为查询字符串)type: "POST",//这是 POST 还是 GET 请求dataType: 'html',//我们期望返回的数据类型success: function (data) {//请求成功时运行的代码;响应传递给函数$("#theModal").modal("隐藏");//关闭正在进行的模态.....$('#ratesView').html(data);//用结果填充div},error: function (xhr, status) {//请求失败时运行的代码;原始请求和状态代码被传递给函数$("#theModal").modal("隐藏");//关闭正在进行的模态.....alert('错误:检索停车费' + "</br>" + xhr.error);}});}////为了取消表单的默认提交并执行AJAX调用,返回false很重要返回假;});});

//第二次更新

按照评论部分中的说明进行操作后,这是来自 ajax 调用的响应:

 <div id="header"><h1>DEFAULT WEB SITE"应用程序中的服务器错误</h1></div><div id="server_version"><p>互联网信息服务 7.5</p></div><div id="内容"><div class="content-container"><fieldset><legend>错误总结</legend><h2>HTTP 错误 404.0 - 未找到</h2><h3>您要查找的资源已被删除、更名或暂时不可用.</h3></fieldset>

<div class="content-container"><fieldset><legend>详细的错误信息</legend><div id="details-left"><table border="0" cellpadding="0" cellspacing="0"><tr class="alt"><th>Module</th><td>IIS Web Core</td></tr><tr><th>通知</th><td>MapRequestHandler</td></tr><tr class="alt"><th>Handler</th><td>StaticFile</td></tr><tr><th>错误代码</th><td>0x80070002</td></tr>

<div id="details-right"><table border="0" cellpadding="0" cellspacing="0"><tr class="alt"><th>请求的 URL</th><td>http://localhost:80/Home/GetRates</td></tr><tr><th>物理路径</th><td>C:inetpubwwwrootHomeGetRates</td></tr><tr class="alt"><th>登录方法</th><td>匿名</td></tr><tr><th>登录用户</th><td>匿名</td></tr><div class="clear"></div>

</fieldset>

<div class="content-container"><fieldset><legend>最可能的原因:</legend><ul><li>指定的目录或文件在 Web 服务器上不存在.</li><li>该 URL 包含印刷错误.</li><li>自定义过滤器或模块,例如 URLScan,会限制对文件的访问.</li></fieldset>

<div class="content-container"><fieldset><legend>可以尝试的事情:</legend><ul><li>在 Web 服务器上创建内容.</li><li>查看浏览器 URL.</li><li>创建跟踪规则以跟踪此 HTTP 状态代码的失败请求并查看哪个模块正在调用 SetStatus.有关为失败的请求创建跟踪规则的详细信息,请单击 <a href="http://go.microsoft.com/fwlink/?LinkID=66439">此处</a>.</fieldset>

<div class="content-container"><fieldset><legend>链接和更多信息</legend>此错误表示该文件或目录在服务器上不存在.创建文件或目录并再次尝试请求.<p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&amp;IIS70Error=404,0,0x80070002,7601">查看更多信息&raquo;</a></p></fieldset>

解决方案

如何调试AJAX调用

完整的答案散布在对 OP 问题的评论中,但我认为这个答案最有帮助:

<块引用>

  1. 转到进行 AJAX 调用的网页
  2. 在 Chrome 中按 F12
  3. 转到网络"标签
  4. 通过提交表单#reservSearch 激活 AJAX 调用
  5. 在网络"选项卡中查找对/Home/GetRates 的调用
  6. 点击它
  7. 检查预览"和响应"选项卡以查看服务器的输出
  8. 它是否显示了您的 AJAX 调用正在侦听的预期 HTML 数据?

I have a web app that works fine on VS 2013 on my development server, but once I published it on the IIS 7.5 2008 R2 server the Ajax scripts, located on my custom script file, don't work anymore, although the other JQuery scripts that do not call Ajax do work properly. Is there anything else that needs to be done in order to have ajax working in the server? I've read some posts about, but couldn't find an answer yet. I've limited experience in IIS and Ajax.

// Update:

I've already figured out that the Ajax script works and that the problem is most likely in the following line:

"url: '/Home/GetRates', // URL for the request"

Using the debuger I found out that the GetRates() function is not been called in the Remote Server, although it is in the local (Under VS 2013) development server. The only difference that I see is the path, but dont know how to fix it. Below is the Ajax script:

// Retrieve rates and update partial view
$(function () {
    $('#reservSearch').submit(function () {
        if ($(this).valid()) {
            $("#theModal").modal("show");              // Display the in progress.....
            $.ajax({
                url: '/Home/GetRates',                 // URL for the request 
                data: $("#reservSearch").serialize(),  // the data to send (will be converted to a query string)
                type: "POST",                          // whether this is a POST or GET request  
                dataType: 'html',                      // the type of data we expect back   
                success: function (data) {             // code to run if the request succeeds; The response is passed to the function
                    $("#theModal").modal("hide");      // Close the in progress modal.....
                    $('#ratesView').html(data);        // Fill div with results
                },
                error: function (xhr, status) {        // code to run if the request fails; the raw request and status codes are passed to the function
                    $("#theModal").modal("hide");      // Close the in progress modal.....
                    alert('Error: Retrieving parking rates' + "</br>" + xhr.error);
                }
            });
        }
//        // it is important to return false in order to cancel the default submission of the form and perform the AJAX call
        return false;
    });
});

// SECOND UPDATE

After following the directions in the comment section, this is the response from the ajax call:

    <div id="header"><h1>Server Error in Application "DEFAULT WEB SITE"</h1></div> 
<div id="server_version"><p>Internet Information Services 7.5</p></div> 
<div id="content"> 
<div class="content-container"> 
 <fieldset><legend>Error Summary</legend> 
  <h2>HTTP Error 404.0 - Not Found</h2> 
  <h3>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</h3> 
 </fieldset> 
</div> 
<div class="content-container"> 
 <fieldset><legend>Detailed Error Information</legend> 
  <div id="details-left"> 
   <table border="0" cellpadding="0" cellspacing="0"> 
    <tr class="alt"><th>Module</th><td>IIS Web Core</td></tr> 
    <tr><th>Notification</th><td>MapRequestHandler</td></tr> 
    <tr class="alt"><th>Handler</th><td>StaticFile</td></tr> 
    <tr><th>Error Code</th><td>0x80070002</td></tr> 

   </table> 
  </div> 
  <div id="details-right"> 
   <table border="0" cellpadding="0" cellspacing="0"> 
    <tr class="alt"><th>Requested URL</th><td>http://localhost:80/Home/GetRates</td></tr> 
    <tr><th>Physical Path</th><td>C:inetpubwwwrootHomeGetRates</td></tr> 
    <tr class="alt"><th>Logon Method</th><td>Anonymous</td></tr> 
    <tr><th>Logon User</th><td>Anonymous</td></tr> 

   </table> 
   <div class="clear"></div> 
  </div> 
 </fieldset> 
</div> 
<div class="content-container"> 
 <fieldset><legend>Most likely causes:</legend> 
  <ul>  <li>The directory or file specified does not exist on the Web server.</li>  <li>The URL contains a typographical error.</li>    <li>A custom filter or module, such as URLScan, restricts access to the file.</li> </ul> 
 </fieldset> 
</div> 
<div class="content-container"> 
 <fieldset><legend>Things you can try:</legend> 
  <ul>  <li>Create the content on the Web server.</li>  <li>Review the browser URL.</li>    <li>Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul> 
 </fieldset> 
</div> 


<div class="content-container"> 
 <fieldset><legend>Links and More Information</legend> 
  This error means that the file or directory does not exist on the server. Create the file or directory and try the request again. 
  <p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&amp;IIS70Error=404,0,0x80070002,7601">View more information &raquo;</a></p> 

 </fieldset> 
</div> 
</div> 
</body> 
</html> 

解决方案

How to debug AJAX calls

The full answer is spread across the comments on OP's question but I think this one helped the most:

  1. Go to the web page which makes the AJAX call
  2. In Chrome press F12
  3. Go to the Network tab
  4. Activate the AJAX call by submitting the form #reservSearch
  5. In the Network tab look for a call to /Home/GetRates
  6. Click it
  7. Check the Preview and Response tabs to see the output from your server
  8. Is it displaying the expected HTML data which your AJAX call is listening for?

这篇关于为什么 Ajax 脚本没有在 IIS 7.5 Win 2008 R2 服务器上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
C#/.NET最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆