zoukankan      html  css  js  c++  java
  • 重写了下Ajax请求Webservice,顺便复习一下Javascript的闭包概念

    var AjaxRequest = function(){
        //返回处理结果的回调函数
        this.agentCallBack = {};
        //javascript 调用domino代理的方法。
        this.ajaxCallAgent = function(agentParam){
            $.ajax({
            type: "POST",
            url: agentParam.url ,
            data: agentParam.jsondata,
            beforeSend: function(request) {
                 //request.setRequestHeader("User-Agent","Apache-HttpClient/4.1.1 (java 1.5)");
            },
            success: agentParam.agentCallBack,
            error: function(request, errorInfo) {
              alert("agent call failed, please contact your administrator.",errorInfo); // alert("errorInfo = "+errorInfo);
            }
          });
        };
    
        //返回处理结果的回调函数
        this.serviceCallBack = {};
        //调用javascriptWebService方法
        this.CallWebService =function (serviceParam){
            this.serviceCallBack = serviceParam.callBack;
          $.ajax({
            type: "POST",
            url: serviceParam.url ,
            data: serviceParam.soapdata,
            beforeSend: function(request) {
              request.setRequestHeader("Content-Type", "text/xml; charset=gbk"); //
              request.setRequestHeader("SOAPAction", serviceParam.soapaction);
            },
            success: this.serviceCallBack,
            error: function(request, errorInfo) {
              alert("invoke webservice failed, please contact your administrator.");
            }
          });
        }
    
        return this;
    }
    
    /*
    * 调用webservice的参数,目的是在重复调用时,一次初始化固定的数据
    * 变化的参数在调用前初始化不变的默认初始化就可以了
    */
    var serviceParam =function(){
        this.dbPath = $("[name=dbPath]").val();
        this.url = "/"+this.dbPath+ "/wsPurchaseOrder?OpenWebService";            //默认初始化参数
        this.ordernumber = $("[name=fldCgddbh]").val();
        this.soapaction = {};                                //调用前初始化, 需要new 一个参数对象
        this.callback = {};
        this.soapdata = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:DefaultNamespace">'+
                   '<soapenv:Header/><soapenv:Body><urn:orderNumber>'+this.ordernumber+'</urn:orderNumber></soapenv:Body></soapenv:Envelope>';
        return this;
    };
    
    /*
    * 调用代理参数少, 没有action
    * 传递参数
    */
    var agentParam =function(){
        this.dbPath = $("[name=dbPath]").val();
        this.url = "/"+this.dbPath+ "/agent?openagent";                            //默认初始化参数                                                
        this.callback = {};                                        //调用前初始化, 需要new 一个参数对象
        this.jsondata = {};                                        //例如:{ordernumber:ordernumber}
        return this;
    };

     可以拷贝所有代码另存为AjaxRequest.js后引入项目使用

  • 相关阅读:
    FILTER(过滤器)
    HDFS优缺点
    python运算符
    python变量类型
    python变量存储
    python编码问题
    【一:定义】python 简介
    如何学一门新技术
    Django安装
    redis 安装及启动关闭
  • 原文地址:https://www.cnblogs.com/dangkei/p/11943554.html
Copyright © 2011-2022 走看看