博文

目前显示的是标签为“XMLHttpRequest”的博文

Return JSON from a JSP

图片
I need using a JSP returns JSON, so wrote the following codes for testing. Fortunately i t works. /*  This file name is json.jsp. It posts itself, then get JSON. */ <%response.setHeader("Cache-Control", "no-cache");%> <%response.setHeader("Pragma", "no-cache");%> <% String t = request.getParameter("t"); if(t==null){ %> <!DOCTYPE html> <% response.setHeader("contentType","text/html;charset=UTF-8"); %> <script type="text/javascript">   var XHR;   function requestJSON(){       if ( window.XMLHttpRequest )          XHR = new XMLHttpRequest();       else if ( window.ActiveXObject ) {          try {             XHR = new ActiveXObject('Msxml2.XMLHTTP');          }      ...