Extjs 4.2:如何在 Ext.Ajax.Request POST 中正确发送参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17185814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extjs 4.2: How to send parameters properly in a Ext.Ajax.Request POST
提问by mannuk
I have to do a POST from my ExtJs script in order to delete something from my DB:
我必须从我的 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');}
});
when the post is sent i can see in the firebug the rolename in font but not as a param. I would like to show you another post (made with spring:form) relative to the user registration. If i inspect the post i can see the following:
发送帖子时,我可以在萤火虫中看到字体中的角色名称,但不是参数。我想向您展示另一篇关于用户注册的帖子(用 spring:form 制作)。如果我检查帖子,我可以看到以下内容:

(source: subirimagenes.com)

(来源:subirimagenes.com)
And i can get the parameters in my controller using @RequestParam.
我可以使用@RequestParam 在我的控制器中获取参数。
But in the post that i have problems i can't see the parameters part, i can only see the Font(Fuente) part:
但是在我遇到问题的帖子中,我看不到参数部分,我只能看到 Font(Fuente) 部分:

(source: subirimagenes.com)

(来源:subirimagenes.com)
As a consequence, my spring controller does not detect any parameter. Is it something wrong in my POST?
结果,我的弹簧控制器没有检测到任何参数。我的帖子有问题吗?
Thank you
谢谢
采纳答案by Reimius
The problem is that you are using the line headers: {'Content-Type': 'text/html'},in your original question. This would set the content to text/html instead of the content being post data.
问题是您headers: {'Content-Type': 'text/html'},在原始问题中使用了该行。这会将内容设置为 text/html 而不是发布数据的内容。
回答by mannuk
I solved it with the following code:
我用以下代码解决了它:
var rolename = 'myRol';
Ext.Ajax.request({
url: 'deleteRole.html',
method: 'POST',
params: {
rolename: rolename
},
success: received,
failure: function(){console.log('failure');}
});
回答by paddys_1
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.
我在 Sencha Touch 应用程序中使用它。我必须添加一个名为 jsonData 的额外配置并使其为真,否则不会将任何内容传递给我的端点 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);
}
});

