以jsp來說,從server side要把想輸出的資料寫到一個檔案中, for example
result.jsp
<% String xxxx= (String)request.getSession().getAttribute(oooo); out.println(xxxx); %>
Step 2:
接著寫一段receive的javascript code把剛剛的檔案讀出來,for example
loadDoc:function(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange=function()
{
if (ajaxRequest.readyState==4 && ajaxRequest.status==200)
{
alert(ajaxRequest.responseText);
}
}
ajaxRequest.open("GET", "result.jsp" , true);
ajaxRequest.send();
即大功告成,至於傳request和接response的java script程式碼,要放在哪裡, 要根據自己的應用程式來決定,相信大家都沒問題的
沒有留言:
張貼留言