I've already read those questions but none of them answer to my need:
(the latest one said just add hard-coded quotes ie ['']
but I can't do this, I'm calling a function that returns an Array)
So here's my code (note that the problem lies to the empty array new Array()
):
function AjaxSend() {
$.ajax({
url: '/json/myurl/',
type: 'POST',
dataType: 'jsonp',
data : { 'tab':new Array() },
context: this,
success: function (data) {
if (data.success) {
console.log('ok');
}
else {
console.log('error');
}
}
});
}
Simple eh?
Here's my Php code:
echo '_POST='.var_export($_POST,true)."
";
And here's the result:
_POST=array (
)
jQuery1710713708313414827_1329923973282(...)
If I change the empty Array by a non-empty, i.e.:
'tab':new Array({ 't':'u' },{ 'v':'w' })
The result is:
_POST=array (
'tab' =>
array (
0 =>
array (
't' => 'u',
),
1 =>
array (
'v' => 'w',
),
),
)
jQuery1710640656704781577_1329923761425(...)
So this clearly means that when there's an empty Array() to be sent, it is ignored, and it's not added to the POST variables.
Am I missing something?
PS: my jQuery version is from the latest google CDN i.e.:
http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
and
http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js
I want the array to be sent, even if it's empty (= send []
)!
Any solution? Any idea? I've already tried to add this option traditional: true
without success.
See Question&Answers more detail:
os