代码无法在IE8和Mozilla Firefox上运行

code is not working on IE8 and Mozilla Firefox

本文关键字:Mozilla Firefox 运行 IE8 代码      更新时间:2023-09-26

我正在使用JSP&Servlet。

我使用gson2.22

当我在google chrome 24.0.1312.57 m上运行以下代码时,它运行良好,但当我尝试在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);
        }

如果我遗漏了什么,请告诉我。。

提前感谢。。。。

试试这个:

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

试试这个链接jQuery函数。in IE不支持大多数Jquery插件。否则,测试JavaScriptlintErrors。JavaScript在线lint错误

相关文章: