i need to call a servlet from javascript by using ajax post method and also need to send some parameters to that servlet. How can i do that. I have spent too much time to get rid of this but still no luck...! All help appreciated.....Please help
Asked
Active
Viewed 9,890 times
0
-
Any code you already tried? [Here](http://api.jquery.com/jQuery.post/) is it already quite good explained... – sp00m Aug 27 '12 at 08:59
-
1check this.http://stackoverflow.com/questions/3028490/calling-a-java-servlet-from-javascript – Sajith Aug 27 '12 at 09:02
3 Answers
2
Try this ...
jQuery.ajax({
url:URL,
data:{"key1":"value1","key2":"value2"},
type:'POST',
dataType : 'xml', /* use 'jsonp' for cross domain*/
success:function(data, textStatus, jqXHR){
// access response data
},
error:function(data, textStatus, jqXHR){
console.log('Service call failed!');
}
});

Jasim Mahamood
- 46
- 3
-
Serves files uploaded via the File Upload demo File Servlet FileUploadServlet com.analytica.net.upload.FileUploadServlet FileUploadServlet /FileUploadServlet
0
Try this
$.ajax({
type : 'GET',
url : '${pageContext.request.contextPath}/Servletname',
data : $('#formname').serialize(),
success : function(response) {
alert(response)
}
});

jitesh
- 14