簡體   English   中英

為什么Ajax腳本沒有在IIS 7.5 Win 2008 R2服務器上運行?

[英]Why the Ajax script is not running on IIS 7.5 Win 2008 R2 server?

我有一個在我的開發服務器上的VS 2013上運行良好的Web應用程序,但是一旦我在IIS 7.5 2008 R2服務器上發布它,位於我的自定義腳本文件上的Ajax腳本就不再工作了,盡管其他JQuery腳本不調用Ajax的工作正常。 為了讓ajax在服務器上工作,還有什么需要做的嗎? 我已經閱讀了一些帖子,但還沒有找到答案。 我在IIS和Ajax方面的經驗有限。

//更新:

我已經發現Ajax腳本有效,問題最有可能發生在以下行:

“url:'/ Home / GetRates',//請求的網址”

使用debuger我發現遠程服務器中沒有調用GetRates()函數,盡管它位於本地(Under 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. 轉到進行AJAX調用的網頁
  2. 在Chrome中按F12
  3. 轉到“網絡”選項卡
  4. 通過提交表單#reservSearch激活AJAX調用
  5. 在“網絡”選項卡中,查找對/ Home / GetRates的調用
  6. 點擊它
  7. 檢查“預覽”和“響應”選項卡以查看服務器的輸出
  8. 它是否顯示您的AJAX調用正在偵聽的預期HTML數據?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM