11

为了从我的数据库中删除某些内容,我必须从我的 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');}
});

发送帖子时,我可以在萤火虫中看到字体中的角色名,但看不到参数。我想向您展示另一篇与用户注册相关的帖子(使用 spring:form 制作)。如果我检查帖子,我可以看到以下内容:

图片
(来源:subirimagenes.com

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

但是在我有问题的帖子中,我看不到参数部分,我只能看到 Font(Fuente) 部分:

图2
(来源:subirimagenes.com

结果,我的弹簧控制器没有检测到任何参数。我的帖子有问题吗?

谢谢

4

3 回答 3

11

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

于 2013-06-19T13:16:03.327 回答
8

我用以下代码解决了它:

var rolename = 'myRol';
Ext.Ajax.request({
    url: 'deleteRole.html',
    method: 'POST',          
    params: {
        rolename: rolename
    },
    success: received,                                    
    failure: function(){console.log('failure');}
});
于 2013-06-19T08:45:12.467 回答
7

I'm using this in a Sencha Touch app. I had to add an extra config called jsonData and make it true or else nothing is passed to my endpoint 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);
    }
});
于 2015-03-06T23:17:01.720 回答