$.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("=", "");

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("", "=");

// 查询是否为

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;    }   }

更多推荐

java 调用ajax_JAVA AJAX调用