2016-10-07 41 views
0

「Uncaught ReferenceError:function_name is not defined」總是在點擊按鈕時彈出,但函數已經定義在頂部。想不出什麼錯誤......jsonTest.jsp:43 Uncaught ReferenceError:requestJson未定義

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

的問題是你的jQuery注射。

外部腳本必須是這樣的:

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

是的,你是對的。謝謝。 – Frank

相關問題