2013-09-30 48 views
0

我正在jsp中創建一個頁面。基本上將我的html設計轉換爲jsp頁面。使用Apache Tomcat作爲服務器。Ajax先決條件失敗錯誤

我的問題是我想通過Ajax調用在表單submit.I上得到「Error:Precondtion Failed」錯誤。

任何人都可以解決此錯誤。

我的代碼如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="stylesheet" type="text/css" href="./css/asp.css"/> 
<script type="text/javascript" src="./js/jquery-1.7.1.min.js" charset="utf-8"></script> 
<title>Authorize Service Provider Search Page</title> 
<script> 
$(document).ready(function(){ 
$("form").submit(function(e) { 
    alert("hello"); 
e.preventDefault(); 
$.ajax({ 
type: "POST", 
url: "aspSearchResultPage.html", 
success: function() 
{ 
$("#information").load("aspSearchResultPage.html"); 
},// success 
error : function(xhr, textStatus, errorThrown) { 
    alert("Error: " + (errorThrown ? errorThrown : xhr.status)); 
} 
}); 
return false; 
}); 
}); 
</script> 
</head> 
<body class="COMPO"> 
<!-- Wrapper --> 
<div id="wrapper"> 

<!-- Container --> 
    <div id="container" class="resolution_800x600"> 

    <!-- Colonnage --> 
      <div id="colonnes" class="clear"> 

      <!-- Page title --> 
        <h2 class="title_n1_orange">ASP Search Page</h2> 
      <!--/Page title--> 

      <!-- Form Page--> 
      <div class="form">      
         <form name="asp_search_page" id="form_asp_search_id" action="" method="post"> 
         <p class="mandatory">Fields marked with asterisks (<span class="mandatory_code">*</span>) are mandatory.</p> 
         <table class="tables" summary="ASP Search Page" cellpadding="0" cellspacing="3"> 
         <tbody> 
         <!-- First Row --> 
         <tr> 
         <th scope="row"><label for="asp">ASP&nbsp;<b>:</b></label></th> 
         <td><select id="asp" name="asp" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">ABC</option><option value="DEF">DEF</option><option value="GHI">GHI</option><option value="JKL">JKL</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select></td> 

         <th scope="row" colspan="2"><label for="region">Region&nbsp;<b>:</b></label></th> 
         <td><select id="region" name="region" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">APAC</option><option value="DEF">AME</option><option value="GHI">EUMA</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select> 
         </td> 

         <th scope="row" colspan="3"><label for="asp">Cluster&nbsp;<b>:</b></label></th> 
         <td><select id="cluster" name="cluster" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">INDIA&amp;CHINA</option><option value="DEF">CHINA&amp;JAPAN</option><option value="GHI">INDIA&amp;HONGKONG&amp;JAPAN</option><option value="JKL">UNITED STATES&amp;CHILE</option><option value="MNO">CANNADA &amp; BRAZIL</option><option value="PQR">DENMARK&amp;EGYPT&amp;FINLAND</option><option value="STU">EGYPT&amp;FRANCE</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select> 
         </td> 

         </tr> 
         <!--/First Row--> 
         <!-- Second Row --> 
         <tr> 
         <th scope="row"><label for="asp">Country&nbsp;<b>:</b> 
         </label> 
         </th> 
         <td><select id="country" name="country" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">INDIA</option><option value="DEF">CHINA</option><option value="GHI">FRANCE</option><option value="JKL">PARIS</option><option value="MNO">EGYPT</option><option value="PQR">CARIO</option><option value="STU">BRAZIL</option><option value="VWX">CANNADA</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select></td> 
         <th scope="row" colspan="2"><label for="asp">SSC 
           Support&nbsp;<b>:</b> </label> 
         </th> 
         <td><select id="cluster" name="cluster" class="field_size_e"><!--<optgroup label="Groupe 1">--><option value="ABC">ABC</option><option value="DEF">DEF</option><option value="GHI">GHI</option><option value="JKL">JKL</option><!--</optgroup><optgroup label="Groupe 2">--><!--</optgroup>--></select> 
         </td> 

         <th scope="row" colspan="3"><label title="Oracle_Code" for="Oracle_Code">Oracle Code&nbsp;<b>:</b> 
         </label> 
         </th> 
         <td><input maxlength="10" name="Oracle_Code" id="Oracle_Code_id" class="field_size_e" type="text" /> 
         </td> 
         </tr> 
         <!--/Second Row--> 
         <!-- Third Row --> 
         <tr> 
         <th scope="row"><label title="CC_ID" for="CC_ID">Clarify 
           Contract ID&nbsp;<b>:</b> 
         </label> 
         </th> 
         <td><input maxlength="10" name="CC_ID" id="CC_ID" class="field_size_e" type="text" /></td> 

        </tr> 
        <tr><td>&nbsp;</td></tr> 
         <!--/Third Row--> 
         <!-- Fourth Row --> 
         <tr>  
         <td colspan="2">&nbsp;</td>        
         <td colspan="2"> 
          <button type="submit" class="button_action_standard"> 
           <span>Search</span> 
          </button></td> 
         <td> 
         <button type="reset" class="button_action_standard"> 
           <span>Reset</span> 
          </button> 
         </td> 

         </tr> 
         <!--/Fourth Row--> 
         </tbody> 
         </table> 
         </form> 
      <!-- Content to be displayed--> 
      <div id="information"></div> 
      <!--/Content to be displayed--> 
      </div> 
      <!--/Form--> 

      </div> 
    <!--/Colonnage--> 

    </div> 
<!--/container--> 
</div> 
<!--/wrapper--> 
</body> 
</html> 
+0

您好,任何一個可以幫助解決錯誤 – Priya

+0

的方法是wrong.In的js您發佈值aspSearchResultPage.html,然後再獲取的成功了嗎?你想做什麼?通過編輯問題解釋更多 –

+0

@DineshKumar是的,我明白這種做法是錯誤的。我想訪問該文件並在div標籤中顯示內容。即基本上aspSearchResultPage.html的結果應填充在<! - 要顯示的內容 - >

<! - /要顯示的內容 - > – Priya

回答

0

@Priya我希望你用struts。通過操作發送您的請求並將請求轉發到您需要加載的jsp頁面。返回與響應相同的jsp頁面作爲數據(此處),並填充您的div。查找下面的代碼片段以達到您的目的。您需要根據您的需要修改代碼。

$.ajax({ 
    url : "yourAction.do?method=yourMethod", 
    type : "POST", 
    async : false, 
    success : function(data) { 
     $("#information").html(data); 
    } 
}); 

讓我知道,如果這有助於..

+0

感謝Vinoth。我會嘗試你提出的同樣的解決方案。 – Priya

相關問題