gpt4 book ai didi

jquery - 为什么 Ajax 脚本无法在 IIS 7.5 Win 2008 R2 服务器上运行?

转载 作者:行者123 更新时间:2023-12-03 22:23:09 25 4
gpt4 key购买 nike

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

//更新:

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

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

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

// 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;
});
});

//第二次更新

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

    <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:\inetpub\wwwroot\Home\GetRates</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>

最佳答案

如何调试 AJAX 调用

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

  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?

关于jquery - 为什么 Ajax 脚本无法在 IIS 7.5 Win 2008 R2 服务器上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21533285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com