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 6672703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:32:22+00:00 2026-05-26T03:32:22+00:00

Why does jQuery add numerical indices to arrays in GET requests with .ajax() ?

  • 0

Why does jQuery add numerical indices to arrays in GET requests with .ajax()? Is there a way to remove those?

For example, in jQuery, let’s say I send the following in as data to .ajax():

var source = {
    "type": "database",
    "criteria": {
      "match": "all", 
      "rules": [{"equals": 1, "val": "test"}, {"equals": 1, "val": "two"}]
    }

I want the rules var to be serialized as an array. This gets serialized as the following url that .ajax() uses:

api?source[type]=database&[criteria][rules][0][equals]=1&source[criteria][rules][0][val]=test&source[criteria][rules][1][equals]=1&source[criteria][rules][1][val]=two

Because the arrays are indexed (rules[0] and rules[1]), it gets interpreted on the server as:

"rules"=>{"0"=>{"equals"=>"1", "val"=>"test"}, "1"=>{"equals"=>"1", "val"=>"test"}}

Ack, it’s now an object! What I need is for it to be serialized as such:

api?source[type]=database&[criteria][rules][][equals]=1&source[criteria][rules][][val]=test&source[criteria][rules][][equals]=1&source[criteria][rules][][val]=two

using rules[] (no index). This then gets correctly interpreted as:

"rules"=>[{"equals"=>"1", "val"=>"test"}, {"equals"=>"1", "val"=>"test"}]

An array!

Is there a setting to control this with ajax? I’ve played around with different settings like dataType and traditional with no luck.

I’m assuming using var[] (no index) is correct as I’ve seen it in examples in jQuery documentation:

$.get("test.php", { 'choices[]': ["Jon", "Susan"]} );
  • 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-26T03:32:23+00:00Added an answer on May 26, 2026 at 3:32 am

    I don’t believe you can change the way that jQuery does that. If I were you, I would write a quick function to generate the parameter you want from your array as a string and then tack that parameter on to the ajax request using the data property as seen below:

    $.ajax({
       type: "GET",
       url: "some.php",
       data: "name=John&location=Boston",
       success: function(msg){
         alert( "Data Saved: " + msg );
       }
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to remove the Now button from the jquery timepicker add
Does jQuery validation plugin have some dependencies? For example, I saw blogposts that said
This does it incorrectly: Can jQuery add commas while user typing numbers? $('input.number').keypress(function(event){ if(event.which
Does anyone know of a way to add a border to a table row
Does anybody know of a way to make jQuery Mobile load only on pages
In javascript/jQuery, is there a way to identify a word in a text block/paragraph?
Is it possible with jquery to add new style declarations? For example, pass: {
I'm trying to find a simple way with jquery to add a transparent caption
Does jQuery - or one of it's plugins - have equivalent functionality to the
does jquery have any plugin that prevents entering any input to a textbox that

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.