“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>
答案 0 :(得分:0)
问题是你的jquery注射。
外部脚本必须如下:
<script src="${pageContext.request.contextPath}/js/jquery-1.4.4.min.js"></script>