Extjs 4.2:如何在Ext.Ajax.Request POST中正确发送参数

时间:2013-06-19 07:54:59

标签: ajax extjs extjs4 extjs4.2

我必须从我的ExtJs脚本中执行POST才能从我的数据库中删除某些内容:

Ext.Ajax.request({
    url: 'deleteRole.html',
    method: 'POST',          
    headers: {'Content-Type': 'text/html'},
    waitTitle: 'Connecting',
    waitMsg: 'Sending data...',                                     
    params: {
        "rolename" : rolename
    },
    scope:this,
    success: received,                                    
    failure: function(){console.log('failure');}
});

发送帖子时,我可以在firebug中看到字体中的rolename,但不能作为参数。我想向您展示相对于用户注册的另一篇文章(由spring:form制作)。如果我检查帖子,我可以看到以下内容:

image http://s2.subirimagenes.com/otros/previo/thump_8498731post.jpg

我可以使用@RequestParam在我的控制器中获取参数。

但是在帖子里我有问题我看不到参数部分,我只能看到字体(Fuente)部分:

image2 http://s2.subirimagenes.com/otros/previo/thump_8498737delete.jpg

因此,我的弹簧控制器没有检测到任何参数。我的POST是不是有问题?

谢谢

3 个答案:

答案 0 :(得分:10)

问题是您在原始问题中使用了行headers: {'Content-Type': 'text/html'},。这会将内容设置为text / html,而不是将内容设置为发布数据。

答案 1 :(得分:8)

我用以下代码解决了它:

var rolename = 'myRol';
Ext.Ajax.request({
    url: 'deleteRole.html',
    method: 'POST',          
    params: {
        rolename: rolename
    },
    success: received,                                    
    failure: function(){console.log('failure');}
});

答案 2 :(得分:5)

我在Sencha Touch应用中使用它。我必须添加一个名为jsonData的额外配置并将其设为true,否则不会将任何内容传递给我的端点URL。

Ext.Ajax.request({
    url: endpoint,
    method : "POST",
    headers: {
        'Content-Type': 'application/json'
    },
    params : {add: formattedAddress, lat: latitude},
    jsonData: true,
    useDefaultXhrHeader : false,
    withCredentials: true,                
    success : function(response) {
        Ext.Msg.alert("Success", 'yea');
    },
    failure : function(response) {
        var respObj = Ext.JSON.decode(response.responseText);
        Ext.Msg.alert("Error", respObj.status.statusMessage);
    }
});