Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:35:08+00:00 2026-05-30T06:35:08+00:00

I’ve already read those questions but none of them answer to my need: Testing

  • 0

I’ve already read those questions but none of them answer to my need:

  • Testing for an empty array object in JSON with jQuery
  • jQuery 1.4.4+ AJAX request – post empty array or object becomes string
  • Cannot access data from jQuery Ajax request, returns empty array
  • JQuery removes empty arrays when sending

(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)."\n";

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:35:09+00:00Added an answer on May 30, 2026 at 6:35 am

    The problem is that you can’t really send empty array. Have you tried to send an empty array manually? How would that uri look (note that it’s the same reasoning for POST)?

    /path?arr[]
    

    This would result in a $_GET like this:

    array (
     'arr' => array (
        0 => ''
      )
    )
    

    That’s not really an empty array, is it? It’s an array with a single element of an empty string. So what jQuery does, and I would agree that this is the correct way of handling it, is to not send anything at all.

    This is actually really simple for you to check on the server. Just add an extra check whether the parameter exists or not, i.e:

    $tabs = array();
    if(isset($_POST['tab'])) {
      $tabs = $_POST['tab'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I am confused How to use looping for Json response Array in another Array.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.