• ajax get,post提交數據


    //ajaxRead("http://page.aspx?aa=jj&bb=3434",post);

    function ajaxRead(file,type){
      var xmlObj = null;
      if(window.XMLHttpRequest){
          xmlObj = new XMLHttpRequest();
      } else if(window.ActiveXObject){
          xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
      } else {
          return;
      }
      xmlObj.onreadystatechange = function(){
        if(xmlObj.readyState == 4){

            //回調函數
            callback(xmlObj.responseText);
         }
        }

        if(file.indexOf("?")>-1)
        {
            file+="&r="+Math.random();
        }
        else
        {
            file+="?r="+Math.random();
        }    
        
        switch(type.toUpperCase())
        {
            case "GET":
                xmlObj.open ('GET', file, true);
                xmlObj.send (null);
                break;
            case "POST":
                xmlObj.open("POST",file,true);
                xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                var querystring=file.substr(file.indexOf("?")+1);
                xmlObj.send(querystring);
                break;
             default:
                 break;
        }
      }


      function callback(response)
      {
        //返回值的處理
        alert(response);
      }
  • 相关阅读:
    项目冲刺之任务场景分析
    一位数组的最大子数组(debug版)
    软件工程课堂五(地铁项目的优化)
    人月神话阅读笔记02
    软件工程第七周总结
    人月神话阅读笔记01
    软件工程第六周总结
    构建之法阅读笔记03
    软件工程第五周总结
    软件工程课堂四(合作开发项目-地铁线路查询)
  • 原文地址:https://www.cnblogs.com/wang123/p/1125032.html
Copyright © 2020-2023  润新知