jquery用jsp文件内容替换div内容

时间:2015-11-22 11:49:36

标签: javascript jquery html jsp

我正在尝试用jsp文件内容替换div内容,但我得到了#34; Uncaught SyntaxError:Unexpected token ILLEGAL"错误。

如果jsp文件有一行它工作正常,但是这个问题发生在jsp有多行时。

test.jsp文件:

    <%@ 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>
<script type="text/javascript">
$(document).ready(function(){
    $("#content").html("<jsp:include page='dashboard.jsp'></jsp:include>");
});
</script>
</head>

<body>
<div id="content">123</div>
</body>
</html>

dashboard.jsp文件:

<div id='test'>
    dashboard
</div>

1 个答案:

答案 0 :(得分:1)

试试这段代码。我在jquery中使用了load函数。

html page

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
    <script type="text/javascript">
       $(document).ready(function(){
           $('#selectedTarget').load('try.jsp');
       });
    </script>   
</head>
 <body>
    <div id="selectedTarget">
        Existing content.
    </div>
    <div>
        Existing content.
    </div>
</body>

try.jsp页面(我不知道jsp所以我只是在jsp文件中写下了这一行)

这是尝试

相关问题