0

我们应该在 senchatouch2 中发送json 数组还是普通数组作为查询字符串

4

2 回答 2

0

无论如何,您只能在 URL 中发送字符串,因此如果您有 JSON,则使用E​​xt.JSON.encode使其成为字符串,如果您有 JS Array 使用toStringjoin方法在将数组附加到 URL 之前将其展平。

既然你说的是查询字符串,所以我想你并没有做 POST 请求。

[编辑] 查看您的评论,您似乎想向服务发送一些数据以进行创建,但在这种情况下,您不应将数据作为查询字符串发送,而应在消息正文中发送。以下是将 JSON 数据发送到您的服务的示例:

var obj = new Object();
obj.loginEntry  = new Object();
obj.loginEntry.userid = username;
obj.loginEntry.password = password;
var data = Ext.JSON.encode(obj);
Ext.Ajax.request({
        url : 'http://myserver:port/service/entity',
        method : "POST",
        headers: {
            /* Important because default is 
             * Content-Type:application/x-www-form-urlencoded; charset=UTF-8 
             * which is not supported by service
             */
            'Content-Type': 'application/json'
        },
        params : data,
        success : function(response) {
        },
        failure : function(response) {
        }
    }
);

[/编辑]

于 2013-04-12T07:33:27.430 回答
0

虽然我们在 Sencha Touch2 中使用 POST 方法发送参数,但在 Ajax 请求中使用jsonData ,例如,

Ext.Ajax.request({ url:'', method:'POST', disableCaching:false, headers: { 'Accept':'application/json', 'Content-Type':'application/json' }, jsonData : { FirstName:fname //{"FirstName":["Sam","paul"]} },成功:function(response) { console.log(response.responseText); },失败:function(response) { console.log日志(response.responseText);},});

于 2013-04-20T04:42:30.330 回答