简体   繁体   English

jQuery的帖子不适用于参数

[英]jquery post not work with params

I can't figure out what i am doing wrong, this code 我无法弄清楚我在做什么错,这段代码

url = '?D=cp&C=addons_modules&M=show_module_cp&module=myaddon&method=test';
var selections = [1,2,3,4];
processBegin();
$.post(url, {ids: selections}, function(data) {
    alert(data)
},
"json");

return NULL, but if I send this (without {ids: selections}) 返回NULL,但如果我发送此消息(不带{ids:selections})

url = '?D=cp&C=addons_modules&M=show_module_cp&module=myaddon&method=test';
var selections = [1,2,3,4];
processBegin();
$.post(url,  function(data) {
    alert(data)
},
"json");

working well. 运作良好。 What amI doing wrong? 我究竟做错了什么?

Thanks 谢谢

Http headers Http头

http://eeclean/system/index.php?D=cp&C=addons_modules&M=show_module_cp&module=myaddon&method=test&products=

POST /system/index.php?D=cp&C=addons_modules&M=show_module_cp&module=myaddon&method=test&products= HTTP/1.1
Host: eeclean
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept: */*
Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Content-Length: 47
Cookie: exp_last_visit=1327226896; exp_last_activity=1327235643; exp_sessionid=331607e53eef40182ecaac80c9a42e66ecc9ebb7; PHPSESSID=f8a8bf96541f0dcbf56645ccc83311e3; exp_anon=1; exp_expiration=1327235644
Pragma: no-cache
Cache-Control: no-cache
ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3&ids%5B%5D=4

You should serealize js array to post it as param or send it as string.(using another way) 您应该确定js数组以将其发布为param或将其作为字符串发送。(使用另一种方式)

var selections = [1,2,3,4];

Like this: 像这样:

$.post(url, {'ids[]': selections}, function(data) {
    alert(data)
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM