2013-02-08 67 views
-1

我正在開發一個使用JSP的Web應用程序& Servlet。代碼不適用於IE8和Mozilla Firefox

我使用google chrome 24.0.1312.57 mgson2.2.2

當我運行下面的代碼它工作正常,但是當我嘗試在IE8Mozilla Firefox 3.6.13運行相同的代碼,那麼相同的代碼沒有完全填滿combobox

HTML:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Testing Browser</title> 
<script src="http://code.jquery.com/jquery-latest.min.js"></script> 

<script> 
$(document).ready(function() { 
     alert('in'); 
     //fill Salutation 
     var $ul = $(SALUTATION); 
     $.get('MyServlet?action=cmbSALUTATION', function(responseJson) { 
      $.each(responseJson, function(index, item) { 
       $('<option>').text(item).appendTo($ul); 
      }); 
     }); 
    }); 
</script> 
</head> 

<body> 
    <table> 
     <tbody> 
      <tr> 
       <td>Salutation</td> 
       <td><select name="SALUTATION" id="SALUTATION"> </select></td> 
      </tr> 
     </tbody> 
    </table> 
</body> 
</html> 

的Servlet:

//COMBOBOX - Get the data for column SALUTATION 
     if(request.getParameter("action")!=null) 
     if(request.getParameter("action").equalsIgnoreCase("cmbSALUTATION")) 
     { 
      String s2[][] = select.getData("select TITLE_ID from CRM_TITLE"); 
      List<String> list = new ArrayList<String>(); 
      for(int i=0;i<s2.length;i++) 
      { 
       list.add(s2[i][0]); 
      } 
      String json = new Gson().toJson(list); 
      response.setContentType("application/json"); 
      response.setCharacterEncoding("UTF-8"); 
      response.getWriter().write(json); 
     } 

請讓我知道,如果我失去了一些東西..

在此先感謝....

+0

一個servlet使用這個JSP來編寫帶有JavaScript的HTML,它調用另一個servlet來獲取你隨後放入HTML的東西。爲什麼原始servlet無法獲得您在此JSP中使用c:forEach所需的信息,而不是以這種方式使您的生活複雜化? – 2013-02-08 12:19:55

+0

@EdDaniel感謝您的建議 – Bhushan 2013-02-08 12:47:05

+0

@DownVoters downvoting的原因將不勝感激 – Bhushan 2013-02-09 04:00:51

回答

0

試試這個:

var $ul = $('#SALUTATION'); // <----id selector 
    $.get('MyServlet?action=cmbSALUTATION', function(responseJson) { 
     $.each(responseJson, function(index, item) { 
      $('<option />').text(item).val(index).appendTo($ul); 
     }); //----^^^^^^-----------------------------try with this 
    }); 
+0

感謝您的回答,但這仍然只適用於Chrome瀏覽器,而不是在IE和Mozilla – Bhushan 2013-02-08 12:10:12

+0

檢查,如果ie和Mozilla已啓用javascript。 – Jai 2013-02-08 12:20:16

+0

我檢查了它,mozilla已啓用javascript – Bhushan 2013-02-08 12:24:38

0

試試這個鏈接jQuery Function。大多數Jquery插件在IE中不受支持。 否則測試JavaScript lint錯誤。 JavaScript Online lint Error

+0

感謝您的回答,我已使用[JavaScript Online lint Error](http://www.javascriptlint.com/online_lint.php)測試JavaScript lint錯誤,但在javascript中沒有錯誤 – Bhushan 2013-02-08 12:19:36

相關問題