首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

Extjs的form传递参数有关问题

2012-12-29 
Extjs的form传递参数问题。本帖最后由 showbo 于 2012-08-10 10:49:19 编辑addEmployee.jsp中的form表单代

Extjs的form传递参数问题。
本帖最后由 showbo 于 2012-08-10 10:49:19 编辑 addEmployee.jsp中的form表单代码

Ext.onReady(function() {
    var form = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 55,
        url:'save-form.php',
        defaultType: 'textfield',
        items: [{
            fieldLabel: '用户名',
            name: 'username',
            anchor:'100%'  // anchor width by percentage
        },{
            fieldLabel: '密码',
            inputType: 'password',
            name: 'password',
            anchor: '100%'  // anchor width by percentage
        },{       
        xtype: 'radiogroup',
            fieldLabel: '性别',
            name:'gender',
          
          items: [
                {boxLabel: '男', name: 'rb-auto', inputValue: 1},
                {boxLabel: '女', name: 'rb-auto', inputValue: 2},            
            ]
        
        }],
           buttons: [{
            text: '保存',
            handler: function(){
            
            Ext.Ajax.request({   
                url : 'manage_add.action', 
       params:{'username':'username','password':'password','gender':'gender'},
                method : 'post',   
                success : function(response) {   
                 Ext.Msg.alert("提示", "方法调用成功");   
                   
                },   


                failure : function() {   
                    Ext.Msg.alert("提示", "方法调用失败");   
                }   
            });  
            
            }
        },{
            text: '重置',
            handler: function(){
            form.form.reset();
            }
      
        }]
    });



manage action的代码:
package cn.feng.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.feng.bean.Employee;
import cn.feng.service.EmployeeService;


@Controller @Scope("prototype")
public class EmployeeManageAction {
@Resource EmployeeService employeeService;
private Employee employee;

public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public String addUI(){
return "add";
}
public String add(){
employeeService.save(employee);
ActionContext.getContext().put("message", "保存成功");
return "message";
}
}

我用标签可以正常提交,用extjs的ajax无法保存过去。请大家帮忙
[解决办法]
params:{'username':'username','password':'password','gender':'gender'},
这种参数传递,不可能封装到:action中的:employee中。
你试试打印employee的值。看看。
[解决办法]
表单域的 name 用 employee.xxx 如名称 那么 名称文本框的name属性改为employee.username这样就能提交到后台action里employee对象里。所有提交的参数都可以在employee拿到。lz试试吧
[解决办法]
 params:{'username':'username','password':'password','gender':'gender'},

你的params参数有问题,这样不是传递输入项的值,而是传递下面描红的内容了'username','password':'password','gender':'gender'

Ext.Ajax.request({   
                    url : 'manage_add.action', 
                       params:form.getForm().getValues() ,//获取表单输入的键值对
                    method : 'post',   
                    success : function(response) {   


                     Ext.Msg.alert("提示", "方法调用成功");   
                       
                    },   
                    failure : function() {   
                        Ext.Msg.alert("提示", "方法调用失败");   
                    }   
                });  


[解决办法]
楼上几位把出问题的地方找出来了,就是这句

params:{'username':'username','password':'password','gender':'gender'},

就是解决方法似乎不太管用。我的方法:

form里的每个item都该有id和name比如:


items: [{
            fieldLabel: '用户名',
            id: 'username',
            name: 'username',
            anchor:'100%'  // anchor width by percentage
        },
        ......


然后在你的ajax里的params里这么调用:


buttons: [{
            text: '保存',
            handler: function(){
             
                    Ext.Ajax.request({   
                    url : 'manage_add.action', 
                     params:{
                     'username': Ext.get('username').dom.value,//注意这样调用参数

                      .........  //这里不一一列举了

                    },
                    method : 'post',   
                    success : function(response) {   
                     Ext.Msg.alert("提示", "方法调用成功");   
                        


                    },   
                    failure : function() {   
                        Ext.Msg.alert("提示", "方法调用失败");   
                    }   
                });  
                 
            }
        },



试一下行不行,如果可以和大家分享,如果不行哪里报错?

[解决办法]
Ext.Ajax.request 本身就是异步提取自己submit,不知道楼上说的不用submit是指什么?

热点排行