jsonTest.jsp:43未捕获的ReferenceError:未定义requestJson

时间:2016-10-07 11:55:18

标签: javascript java jquery jsp

“Uncaught ReferenceError:function_name未定义”单击按钮时总是弹出,但该功能已在顶部定义。无法弄清楚出了什么问题...

jsp源代码如下:

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Json interaction Test</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.4.min.js"/>
    <script type="text/javascript">

        function requestJson() {

            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/requestJson.action",
                contentType: "application/json;charset=utf-8",
                data: "{'name': 'Mobile', 'price': 999}",
                success: function (data) {
                    alert(data);
                }
            });
        }

    </script>
</head>
<body>

    <input type="button" onclick="requestJson()" value="Click"/>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

问题是你的jquery注射。

外部脚本必须如下:

 <script src="${pageContext.request.contextPath}/js/jquery-1.4.4.min.js"></script>