Ajaxgold is also a very short practical 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 both return text and XML.
In the Ajaxgold framework, the returned text is used as a unique parameter 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" "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");
%>