相关文章
更多最近更新
更多最近遇到一个Ext.Ajax.request的奇怪问题
2019-03-25 13:41|来源: 网路
最近在学Extjs,照着视频做了一个提交数据并且添加store的demo,却遇到一个奇怪的问题:添加第一次的时候没有问题,添加第二次的时候就向服务器发了2次请求,添加第3次的时候就向服务器发了3次请求,导致了,第二次添加了2个相同的,第三次添加了3个相同的,请大家帮我看下是哪有写得有问题
问题补充:
回复1楼,如果我把Ext.Ajax.request注掉,直接把record add到store里面又没有问题,不存在多次执行操作的问题
Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = "side"; PersonViewFormPanel = Ext.extend(Ext.form.FormPanel,{ constructor:function(){ PersonViewFormPanel.superclass.constructor.call(this,{ id:"form", layout:"form", defaultType:"textfield", baseCls:"x-plain", style:"padding:5px", defaults:{width:175}, width:240, height:85, labelWidth:45, items:[ {fieldLabel:"姓名",id:"name"}, {fieldLabel:"性别",id:"sex"}, {fieldLabel:"年龄",id:"age"} ] }); } }); PersonInfoFormPanel = Ext.extend(Ext.form.FormPanel,{ constructor:function(){ PersonInfoFormPanel.superclass.constructor.call(this,{ layout:"form", id:"info_form", defaultType:"textfield", baseCls:"x-plain", bodyStyle:"padding:5px", defaults:{width:150}, width:240, height:85, labelWidth:45, items:[ {fieldLabel:"姓名",id:"name",allowBlank:false,blankText:"姓名必须填写!",emptyText:"必填"}, { xtype:"combo", fieldLabel:"性别", emptyText:"请选择", hiddenName:"sex", displayField:"name", valueField:"value", triggerAction:"all", mode:"local", readOnly:true, store:new Ext.data.JsonStore({ fields:["value","name"], data:[{value:0,name:"男"},{value:1,name:"女"}] }) }, {fieldLabel:"年龄",id:"age"} ] }); }, getValues:function(){ if(this.getForm().isValid()) return new Ext.data.Record(this.getForm().getValues()); else throw Error("表单验证未通过!"); }, setValues:function(_record){ this.getForm().loadRecord(_record); }, reset:function(){ this.getForm().reset(); } }); InsertPersonInfoWindow = Ext.extend(Ext.Window,{ form:null, constructor:function(){ this.form = new PersonInfoFormPanel(); InsertPersonInfoWindow.superclass.constructor.call(this,{ title:"添加人员", closeAction:"hide", height:155, width:240, modal:true, plain:true, resizable:false, items:this.form, buttons:[ { text:"确定", handler:function(){ this.onSubmitClick(); }, scope:this },{ text:"取消", handler:function(){ this.onCancelClick(); }, scope:this } ] }); this.addEvents("submit"); }, close:function(){ this.form.reset(); this.hide(); }, onSubmitClick:function(){ try{ this.fireEvent("submit",this,this.form.getValues()); }catch(e){ Ext.Msg.alert("错误",e); } }, onCancelClick:function(){ this.close(); } }); PersonListGridPanel = Ext.extend(Ext.grid.GridPanel,{ InsertWindow:null, constructor:function(){ this.InsertWindow = new InsertPersonInfoWindow(); PersonListGridPanel.superclass.constructor.call(this,{ id:"grid", width:240, autoHeight:true, tbar:[ { text:"添加", handler:function(){ this.InsertWindow.show(); this.InsertWindow.on("submit",function(_window,_record){ Ext.Ajax.request({ url:"test5.pfv", params:_record.data, success:function(_response){ Ext.getCmp("grid").getStore().add( new Ext.data.Record(Ext.util.JSON.decode(_response.responseText))); _window.close(); } }); }); }, scope:this },"-", {text:"修改"},"-", {text:"删除"} ], columns:[ {header:"姓名",dataIndex:"name",width:80}, {header:"性别",dataIndex:"sex",width:80}, {header:"年龄",dataIndex:"age",width:80} ], store:new Ext.data.JsonStore({ autoLoad:true, fields:["name","sex","age"], url:"test4.pfv" }), sm:new Ext.grid.RowSelectionModel({ singleSelect:true, listeners:{ "rowselect":{ fn:function(_rsm,_index,_record){ this.fireEvent("rowselect",_record); }, scope:this } } }) }); this.addEvents("rowselect"); } }); Ext.onReady(function(){ var _grid = new PersonListGridPanel(); // var _form = new PersonViewFormPanel(); var _window = new Ext.Window({ renderTo:Ext.getBody(), title:"测试组件化编程", resizable:false, plain:true, frame:true, items:[ _grid ] }); _window.show(); // _grid.on("rowselect",function(_record){ // this.getForm().loadRecord(_record); // },_form); });
@RequestMapping(value="/test5.pfv") public void test5(HttpServletRequest request, HttpServletResponse response) throws Exception { String name = request.getParameter("name"); String sex = request.getParameter("sex"); String age = request.getParameter("age"); Map<String, String> map = new HashMap<String, String>(); map.put("name", name); map.put("sex", "0".equals(sex)?"男":"女"); map.put("age", age); JSON json = JSONObject.fromObject(map); json.write(response.getWriter());
问题补充:
回复1楼,如果我把Ext.Ajax.request注掉,直接把record add到store里面又没有问题,不存在多次执行操作的问题
相关问答
更多-
我会检查一下sinon js做你的ajax嘲笑。 我们目前正在使用它在我们的Ext重型应用程序中编写单元测试。 http://sinonjs.org/docs/#fakeServer 您应该能够使用以下内容测试您的ajax请求: { setUp: function () { this.server = sinon.fakeServer.create(); }, tearDown: function () { this.server.restore() ...
-
尝试使用Ext.util.JSONP 。 我没有看到使用Ext.Ajax在文档中执行jsonp的方法 Try using Ext.util.JSONP. I don't see a way to do jsonp in the docs using Ext.Ajax
-
检查URL“loginHostUri”是否为null。 您是否正在尝试跨域请求? 在这种情况下,您将无法从浏览器执行此操作(直到您以不安全模式打开浏览器)。 并且Ajax请求通过“params”而不是“extraParams”发送参数。 Check the url "loginHostUri" whether it is null or not. Are you trying a cross domain request? In that case you will not be able to do th ...
-
你需要使用这个: success: function ( result, request ) { var jsonData = Ext.util.JSON.decode(result.responseText); var resultMessage = jsonData.data.result; fn_AKExt(resultMessage, ‘Success’); ...
-
您可以在Ext.Ajax上创建自己的自定义方法,该方法具有默认的失败处理程序。 在这个例子中,我只是为了简单起见而模拟了Ext对象。 //Placeholder for the actual Ext object for the purposes of demonstration var Ext = { Ajax: { request: function (r) { //Simulate a failure r.failure(); } }, ...
-
Ext.Ajax.request变量(Ext.Ajax.request variables)[2024-03-07]
Ext.Ajax.request是asynchrone,这意味着它不会停止并等待请求的返回。 因此,在请求返回之前调用console.log。 你必须在“成功”回调中执行此操作,这是在请求返回时调用的。 Ext.Ajax.request is asynchrone, which mean it doesnt stop and wait for the return of the request. So your console.log is call before the request return. Y ... -
我发布了实际代码的错误部分。 真的很抱歉这个混乱......工作代码是::: Ext.onReady(function() { var array_edited=Ext.create('Ext.data.Store', { storeId:'myArray_edited', fields:['id','name', 'email'], proxy: { type: 'memory', reader: { type: 'json' ...
-
如何让“Ext.Ajax.request”中的变量成为全局变量?(How can let variable in “ Ext.Ajax.request ” become Global variable?)[2023-06-16]
taox的答案是正确的,但我会解释为什么它不起作用。 确保在请求完成后访问变量。 请注意,请求是异步的。 var value; Ext.Ajax.request({ url: 'a/b/c', success: function(response){ var result = Ext.decode(response.responseText); if((result.a)==1){ value = result.a; ... -
谢谢你的回答。 本网站http://jsonlint.com/将 "string
string"为有效的JSON字符串。 但这是一个“错误的”JSON验证,因为它不是正确的JSON格式。 我解决了在控制器的@EequestMapping注释中添加produce="application/json"的@EequestMapping 。 所以现在Ext.JSON.decode()甚至可以用于Firefox。 我还可以使用ajax请求发回一个可序列化的对象,然后解码响应以获取数据(带有我的字符串),因为S ... -
只有当请求在网络级别失败时,它才会调用失败处理程序 - 如果您收到服务器错误或服务器将不返回任何内容。 否则它将成功,您需要解析响应以查看它是否是逻辑故障。 It would call failure handler only when request would failed on the network level - if you get server error or server won't return anything. Otherwise it will be success and you ...