无法在Ext.Ajax.request中设置正确的content-Type [英] can't set correct content-Type in Ext.Ajax.request
问题描述
代码如下:
Ext.Ajax.request({
url: url,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
jsonData: {
textMatchStyle:"substring",
fields: ["packageName","name","tableName"],
data: {_domain:null,_domainContext:{},operator:"and",criteria:[]},
limit: 40,
offset: 0
},
success: function(response) {
console.log('Success');
},// function called on success
failure: function(result) {Ext.MessageBox.alert('Error', 'Some problem occurred');},
});
这应该根据Extjs文档工作,但是在请求标头中
This should work according to Extjs documentation, but in request-header
Content-Type application/x-www-form-urlencoded,text/javascript; charset=UTF-8
这会导致问题,因为我的服务器需要以application/json
格式而不是application/x-www-form-urlencoded
Which causes problem as my server requires post data in application/json
format and not in application/x-www-form-urlencoded
我也在外部论坛上进行了搜索,但是无法正常工作.
I have searched this on ext-forums too but could not get it worked.
我的代码中是否存在问题或extjs中的错误?
Is there Problem in my code or its bug in extjs?
请帮助.
推荐答案
一切正常,因为您的代码可以正常运行.我在IE9和Chrome中都对其进行了测试,如图所示:
Everything is ok with your code because it works ok. I tested it in both IE9 and Chrome and as you can see in the image:
您可以在此处看到此功能: http://tinyurl.com/afeluoy
You can see this working here: http://tinyurl.com/afeluoy
我无法想象为什么您的标头设置不正确,而是在jsfiddle中使用它以确认其正常工作的原因.
I can´t imagine a reason why your header is not setted okay but play with the it in jsfiddle to confirm it works properly.
这篇关于无法在Ext.Ajax.request中设置正确的content-Type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!