首页 > 解决方案 > Uncaught SyntaxError: Invalid or unexpected token when using $(element).html to include jsp

问题描述

我是 JAVA 的新手(JSP 和 JSTL)

我对 api 端点进行 Ajax 调用,在回调中我想加载一个 jsp 文件,其中包含 jsp。所以,我做类似的事情

AjaxQueueManager.get("/xyz/abc/" + efg,
    function(data) {
        if (data.success) {
                $(element).html('<jsp:include page="includes/jsp-file.jsp" />');
        } else {
                getResourcesFailureCallback(element, data.errors, "ocon-wrong", "Something's Wrong!");
        }
    },
    function(error) {
        console.log("#####", error.status, error.statusText);
    }
);

如果我的 jsp-file.jsp 不包含任何 javascript 一切正常,例如,如果我把

<p>Hello World</p>

它工作正常,但是一旦我将 javascript 放入 jsp 文件中,即使是最基本的 javascript

console.log("hello world");

我收到一个错误

Uncaught SyntaxError: Invalid or unexpected token
$(element).html("<script type="text/javascript">

我理解这个错误,它的原因是“混入了”,type="text/javascript"但我不知道如何解决它。

标签: javascripthtmljspjstl

解决方案


推荐阅读