2011-09-28 147 views
0

一旦单击提交按钮,名称文本框上键入的名称将打印在servlet中。但是由servlet发送的响应不会返回给客户端。我不确定我会出错的地方。需要帮忙。JQuery Ajax调用没有从servlet获取响应

JQuery-Ajax我打电话给我的sampleServlet。

HTML页面

<script> 
$(document).ready(function(){ 
$(".Submit").click(function(){ 
nameVal=$("#name").val(); 
alert(nameVal ) ; 
$.get("http://localhost:8080/dummyService/SampleServlet", {name:nameVal}, function(data) {//This function is supposed to be called once the servlet send the response 
alert(data) ; 
$("#flag").html(data) ; 
    }); 
}); 
}); 

</script> 



<form id="sampleform" method="POST"> 
<center> 
Enter your Name: <input id="name" class="name" type="text"> <br/><br/> 
        <input class="Submit" name="Submit" type="button" value="Submit" id="Submit"> 
</center> 
</form> 
<div id="flag"> </div> 

**SampleServlet** 

protected void doGet(HttpServletRequest request, 
       HttpServletResponse response) throws ServletException, IOException { 
    System.out.println("INSIDE DO GET"); 
    String name = request.getParameter("name"); 
    System.out.println(name); 
    response.setContentType("text/plain"); 
    PrintWriter out = response.getWriter(); 
    out.println("Hello " + name); 
    out.flush(); 
    out.close(); 
} 
+0

尝试使用'$ .get(“/ dummyService/SampleServlet”' – Rafay

+0

也可以在萤火虫中看到erros – Rafay

+0

是在端口8080上调用servlet的页面,或者也许是在apache的80端口上,因为这可能是一个问题 – stivlo

回答