at.*_*at. 7 parameters ajax jquery post
我正在使用jQuery做一个简单的AJAX帖子,效果很好:
var parameters = {firstName: 'John', lastName: 'Smith'};
$.post('http://api.example.com/rest', parameters, function(data) {
alert('Response: ' + data.someResult);
});
Run Code Online (Sandbox Code Playgroud)
但是,当我向参数添加数组时,如下所示:
var parameters = {firstName: 'John', lastName: 'Smith', children: ['Susy', 'Billy']};
Run Code Online (Sandbox Code Playgroud)
然后问题是在POST到服务器时参数名称children被更改为children[](它实际上是URL编码children%5B%5D).我无法更改服务器以查找名称参数,children[]所以我该怎么办?如何使用名称发布多个值children?为什么jQuery会更改我的参数名称?
我相信你需要启用traditional参数编码.
请参阅http://api.jquery.com/jQuery.ajax/和http://api.jquery.com/jQuery.param
由于$.post没有针对此的特定选项,您需要还原$.ajax或使用全局设置jQuery.ajaxSettings.traditional = true.