Ajaxgold is also a very short and useful AJAX framework that provides four methods for developers to invoke, respectively, Getdatareturntext (Url,callback); Getdatareturnxml (Url,callback); Postdatareturntext (Url,data,callback); Postdatareturnxml (Url,data,allback);
It's not hard to see that they all return text and XML.
In the Ajaxgold framework, the returned text is used as the only argument to the callback function. So you can write this in the display () function:
function display (text) {
document.getElementById ("Targetid"). Innerhtml=text;
}
The complete code is as follows:
<script type= "Text/javascript" src= "Js/ajaxgold.js" ></script>
<script type= "Text/javascript" >
function display (text) {
document.getElementById ("Targetid"). Innerhtml=text;
}
</script>
<body>
<form action= "" >
<input type= "button" value= "Get the Message" onclick= "Postdatareturntext (' ajaxgold.jsp ', ' a=2&b=3 ', display)" >
</form>
<div id= "Targetid" > Content right here </div>
</body>
Server-side code: ajaxgold.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>
<%
Response.setcontenttype ("Text/xml");
int A=integer.parseint (Request.getparameter ("a"));
int B=integer.parseint (Request.getparameter ("B"));
Out.write (a+b+ "aaaaaaa");
%>