0
我做了一個簡單的表單,點擊提交後發送到AJAX,處理後發送到servlet。我不打印servlet的響應,只是顯示警報,但不起作用。請任何解決方案。 JSP:爲什麼沒有就緒狀態變爲4?
<script type="text/javascript">
var x = new XMLHttpRequest();
function fn1()
{
x.onreadystatechange = fn2();
x.open("GET","servlet1",true);
x.send();
}
function fn2()
{
alert("happy");
if(x.readyState==4)
{
alert("happyness");
}
}
</script>
的Servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("hello");
}
Web的XML:
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>servlet1</servlet-name>
<servlet-class>ajaxeg2.servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
什麼是您的servlet類?是小「s」的「servlet1」嗎? – user0946076422