Bug Tracker

Ticket #2726 (closed enhancement: wontfix)

Opened 6 years ago

Last modified 6 years ago

AJAX functions don't pass JSON with arrays properly

Reported by: lukebrookhart Owned by: flesler
Priority: minor Milestone: 1.2.4
Component: ajax Version: 1.2.3
Keywords: JSON arrays Cc: grabanski@…; jeresig@…
Blocking: Blocked by:

Description

With all the AJAX functions (ie. .load, .post .get, etc) the JSON data that is sent to the server does not pass the array data properly. Due to the way arrays are passed to web servers, the names of the array variables need to be concatenated with "[]" to signal to the server that there is more than one value.

Example:

$('#property_search_results').load('search.php', {towns:['Apalachin','Owego','Binghamton']});

Web servers will first define the "town" variable with "Apalachin". It will then immediately overwrite "Apalachin" with "Owego", and then overwrite "Owego" with "Binghamton".

If we change the variable name to towns[] within the AJAX functions, web servers will know that this is an array of values and all will be well. This is same way that web browsers pass an array of values for one variable in forms and query strings.

Attachments

param.diff Download (1.7 KB) - added by flesler 6 years ago.
This is the change, but I think I won't be able to apply it as many people/servers don't expect this to happen.

Change History

comment:1 Changed 6 years ago by flesler

  • Owner set to flesler
  • Priority changed from major to minor
  • Status changed from new to assigned
  • Component changed from core to ajax
  • Type changed from bug to enhancement

Will look into it.

Changed 6 years ago by flesler

This is the change, but I think I won't be able to apply it as many people/servers don't expect this to happen.

comment:2 Changed 6 years ago by flesler

  • Status changed from assigned to closed
  • Resolution set to wontfix

According to  this, the index/key shouldn't be specified.

So I'll have to close this, you can apply the diff to your file if you want, or you can just use:

{
 'towns[]':['Apalachin','Owego','Binghamton']
}

That should work as expected.

Note: See TracTickets for help on using tickets.