JAVA AJAX调用

$.ajax({
           type: "POST",
           url: 项目地址+"/XX/XX/请求.do",                                 
           data: 'Id='+IdObj.value,
           success: function(msg){
          if(msg=='ok'){
            alert("成功");
          }else{
            alert(msg);
          }
           }
         });

 

 

EXT  AJAX

这下面例子是一个很好的页面请求的示例,因看到比较好奇 所以转之.若有侵权 还请告之.
/**
 * 通过Ajax提交数据到后台处理
 * ajaxSumitData
 *  async: true 异步 false 同步
 *  action: 提交的Action
 *  param: 提交的参数
 *  successFunc: 异步提交时,正确返回的回调函数
 *  failureFunc: 异步提交时,错误返回的回调函数
 * */
var msgTip; // 一定要定义在使用前,且定义为全局变量
function ajaxSubmitData(async, action, param, successFunc, failureFunc){
 var respText;
 
 if(async){
  
  param = '{' + param + '}';
  var objParam = eval('(' + param +')');
  
  Ext.Ajax.request({
   timeout: 600000,
   url:action,
   async :  async,//同步请求数据
   params : objParam,
   method : 'POST',
   success : function(response,options){
      respText = Ext.util.JSON.decode(response.responseText);
      //msgTip.hide();
      if (successFunc != null) {
        if(successFunc(respText)) return; // 执行回调函数
       }
   },
   failure : function(response,options){
         //msgTip.hide();
      if(failureFunc != null){
       if(failureFunc(response.responseText)) return; // 执行回调函数
      }else{
       Ext.Msg.getDialog().setWidth(500);
       Ext.Msg.alert('提示','页面处理请求失败!');
      }
   }
  });
 }else{
     var xml = ajaxInit();//new ActiveXObject("MSXML2.XMLHTTP.4.0");
     xml.open("POST", action, false);
     xml.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded");
     xml.send(param);
     return xml.responseText; 
 }
 return null;
}

 

 

// 同步方法检索数据库中的
function ajaxSearchData(searchField, tableName, condition){
 return ajaxSearchDataWithSort(searchField, tableName, condition, null);
}

//同步方法检索数据库中的
function ajaxSearchDataWithSort(searchField, tableName, condition, sort){
 var param = "";
 param += "s_method=searchData&";
 param += "s_searchField=" + searchField + "&";
 param += "s_tableName=" + tableName + "&";
 condition = condition.replaceAll("=", "<equal>");
 param += "s_condition=" + condition + "&";
 if (sort != null && sort != "") {
  param += "s_sort=" + sort + "&"; 
 }
 return ajaxSubmitData(false, global_ctx + "/search/SearchCommon/dbOptJson.do", param);
}

 

 

后台方法

String method = (String) pr.getFilters().get("method");
  if ("searchData".equals(method)) {
   String con = (String) pr.getFilters().get("condition");
   con = con.replaceAll("<equal>", "=");
   // 查询是否为
   sql = "select " + (String) pr.getFilters().get("searchField");
   sql += " from " + (String) pr.getFilters().get("tableName");
   sql += " where " + con;
   page = searchDao.selectData(sql, pr.getFilters(), pr);
  } else if ("searchDataBySQL".equals(method)) {
   sql = (String) pr.getFilters().get("sql");
   page = searchDao.selectData(sql, pr.getFilters(), pr);
  }

 

 

页面调用 示例

var data = ajaxSearchData("t.cd, t.name", "COMPANY t ", "t.name = '" + name.value + "'");
  if (data != null) {
   o = eval( "(" + data + ")" );
   if (o.totalProperty > 0) {
    companyCd.options.length = 0;
    for ( i = 0; i < o.totalProperty ; i ++){
     var oOption = document.createElement("OPTION");
     oOption.text = o.root[i].name;
     oOption.value = o.root[i].cd;
     companyCd.add(oOption);
    }
    companyCd.selectedIndex = 0;
   }
  }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值