jquery post not work with params

136 views Asked by At

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})

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://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
1

There are 1 answers

7
Oyeme On BEST ANSWER

You should serealize js array to post it as param or send it as string.(using another way)

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

Like this:

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