Dolphinsz 2013-08-14
客户端JS代码
Ext.data.JsonP.request({ url: 'http://localhost:8888/login.do?method=phoneLogin', params:{ loginId:nameValue, password:passwordValue }, callbackKey: 'callback', callback:function(result){ Ext.Msg.alert(result); }, success: function(response) { if(response.success==true){ this.redirectTo('loadmain'); }else{ Ext.Msg.alert('登录失败',response.msg); } }, failure: function() { Ext.Msg.alert('请求失败','AJAX请求发送失败!'); } });
服务端代码
JSONObject result = new JSONObject(); String callback = request.getParameter("callback"); result.put("success",true); modelMap.put("jsonstring",callback+"("+result.toString()+")");
返回值要加上传过来的callback回调函数,这样在客户端解析才不会抛出invalidlabel错误.