Extjs6设置Store、Ajax、form的请求方式(GET、POST)

时间:2023-03-10 01:18:38
Extjs6设置Store、Ajax、form的请求方式(GET、POST)

Extjs6 设置Store、Ajax、form的请求方式(GET、POST)

Ajax请求和Form的submit方法设置请求方式和原来一样,使用method : 'POST'设置

  1. // 表单提交
  2. winForm.getForm().submit({
  3. waitTitle : '提示',// 标题
  4. waitMsg : '正在提交数据请稍后...',// 提示信息
  5. url : '../../../dayReportController/add.do',
  6. method : 'POST',
  7. params : { // 此处可以添加额外参数
  8. extraParems : 'extraParems'
  9. },
  10. success : function(form, action) {
  11. /*
  12. * 第二种方法获取返回值
  13. var success = action.result.success;
  14. alert(success);
  15. */
  16. var respText = Ext.util.JSON.decode(action.response.responseText)
  17. if (respText.success == true) {
  18. Ext.Msg.alert('消息', '保存成功!');
  19. Ext.getCmp('win').close();// 添加成功后关闭窗口
  20. Ext.getCmp('menuGrid').getStore().reload(); // 添加成功后重新刷新表格
  21. } else {
  22. Ext.Msg.alert('消息', respText.msg);
  23. }
  24. },
  25. failure : function(form, action) {
  26. Ext.Msg.alert("消息", "操作失败!");
  27. }
  28. });
  1. Ext.Ajax.request({
  2. method : 'POST',
  3. url : '../../../dayReportController/deleteMenu.do',
  4. params : {
  5. 'id' : id // 要删除记录的id
  6. },
  7. success : function(response, config) {
  8. /*
  9. // 后台:out.print(1);
  10. var result = response.responseText;
  11. if (parseInt(result) == 1) {
  12. Ext.getCmp('menuGrid').getStore().reload();
  13. Ext.Msg.alert("提示", '删除成功!');
  14. } else {
  15. Ext.Msg.alert('提示', '删除失败!');
  16. }
  17. */
  18. // 后台:out.print({success : true});
  19. var json = Ext.util.JSON.decode(response.responseText);
  20. if (json.success == true) {
  21. Ext.getCmp('menuGrid').getStore().reload();
  22. Ext.Msg.alert("提示", '删除成功!');
  23. } else {
  24. Ext.Msg.alert('提示', '删除失败!');
  25. }
  26. },
  27. failure : function() {
  28. Ext.Msg.alert('提示', '删除失败!');
  29. }
  30. });

Store设置请求方式使用   actionMethods : {

read : 'POST'

}

  1. var store = Ext.create('Ext.data.Store', {
  2. // autoLoad : true,
  3. pageSize : main.gridPageSize,
  4. fields : ['id', 'text', 'description', 'url', 'leaf'],
  5. proxy : new Ext.data.HttpProxy({
  6. type : 'ajax',
  7. url : '../../../dayReportController/test.do',
  8. actionMethods : {
  9. read : 'POST' // Store设置请求的方法,与Ajax请求有区别
  10. },
  11. reader : new Ext.data.JsonReader({
  12. type : 'json',
  13. rootProperty : 'data',// 数据(不配置的话无法接收数据),返回的key为data
  14. totalProperty : 'totalRecord'// 记录数(不配置的话无法翻页),返回的key为totalRecord
  15. })
  16. })
  17. });

原文链接:https://blog.csdn.net/diweikang/article/details/48344523