Sometime we need to use the response given by AJAX,outside of AJAX(somewhere else in java script)
here is the approach.
<script language="JavaScript" src="jquery-1.4.2.min.js"></script>
<Script language="JavaScript">
$(document).ready(f1);
function f1()
{
var total = $.ajax({
type: "POST",
url: "add.jsp",
data: "num1=10&num2=20",
async: false
}).responseText;
//use total here
}
</Script>
add.jsp
-------
<%
int sum=Integer.parseInt(request.getParameter("num1"))+Integer.parseInt(request.getParameter("num2"));
out.println(sum);
%>
No comments:
Post a Comment