泥巴麒麟的BLOG

          shenAwesome@hotmail.com 縱不能,將醉做生涯,休拘束

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            195 Posts :: 2 Stories :: 80 Comments :: 0 Trackbacks

          工作需要,寫了些ajax用于驗(yàn)證???

          摘抄一下:

          action中:
          ??
          ? public class CheckIPAction extends Action {
          ????? public ActionForward execute(ActionMapping maping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
          ??????? String message = "hi";
          ???????
          ??????? response.setContentType("application/x-www-form-urlencoded;charset=UTF-8");
          ??????? response.getWriter().write(message);
          ??????? return null;
          ????? }
          ??? }


          ?? jsp中的<script>里:
          ???????? //固定的,可寫個(gè)js
          ???????? function executeXhr(callback, url,info) {
          ???????? if (window.XMLHttpRequest) {
          ??????????? req = new XMLHttpRequest();
          ??????????? req.onreadystatechange = callback;
          ??????????? req.open("POST", url, true);
          ??????????? req.setRequestHeader("Content-Length",info.length);????
          ??????????? req.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
          ??????????? req.send("info");
          ???????? } else if (window.ActiveXObject) {
          ??????????? req = new ActiveXObject("Microsoft.XMLHTTP");
          ??????????? if (req) {
          ????????????? req.onreadystatechange = callback;
          ????????????? req.open("POST", url, true);
          ????????????? req.setRequestHeader("Content-Length",info.length);???
          ????????????? req.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
          ????????????? req.send(info);
          ??????????? }
          ????????? }
          ?????? }
          ?????? function processAjaxResponse() {
          ??????? if (req.readyState == 4) {
          ??????????? // only if "OK"
          ??????????? if (req.status == 200) {
          ?????????????? var res =? req.responseText;
          ?????????????? doResponse(res);
          ??????????? } else {
          ??????????????? alert("There was a problem retrieving the XML data:\n" +
          ??????????????? req.statusText);
          ??????????? }
          ???????? }
          ?????? }
          ???????
          ?????? //下面是需要修改的
          ?????? function sendRequest(){
          ????????? var url = "./checkIPAction.do";
          ????????? var callback = processAjaxResponse;
          ????????? var queryStr = "ips=1";
          ????????? executeXhr(callback, url,queryStr);??????
          ?????? }
          ?????? function doResponse(response){
          ????????????? msg.innerHTML = response;
          ?????? }

          posted on 2007-03-02 17:45 泥巴麒麟 閱讀(137) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 蒙阴县| 伊通| 峡江县| 商洛市| 长丰县| 新和县| 太谷县| 瑞金市| 于都县| 无为县| 枣强县| 广西| 合山市| 永春县| 阜新| 湖南省| 体育| 监利县| 霍林郭勒市| 普格县| 高邮市| 文昌市| 贵阳市| 建平县| 方城县| 岑巩县| 班玛县| 汉阴县| 涿州市| 长春市| 阳城县| 龙江县| 普兰店市| 凤台县| 库伦旗| 托克逊县| 格尔木市| 灵川县| 南京市| 平罗县| 长垣县|