Bug Tracker

Modify

Ticket #9059 (closed bug: invalid)

Opened 2 years ago

Last modified 23 months ago

Incorrect URL using $.ajax for GET with empty value in data

Reported by: Thomas Owned by: Thomas
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.2
Keywords: Cc:
Blocking: Blocked by:

Description

When using $.ajax and an undefined value s part of the data property, the URL produced does not include the key-part.

 $.ajax({
        type: 'GET',
        url: 'http://example.com/SomePage',
        data: {'MyKey': 'value', 'OtherKey': undefined, 'ThirdKey': ''}
    });

Does not include 'OtherKey' in the URL

Expected URL would be  http://example.com/SomePage?MyKey=MyValue&OtherKey=&ThirdKey=

ActualURL is  http://example.com/SomePage?MyKey=MyValue&ThirdKey=

Fiddle:  http://jsfiddle.net/QKmtz/3/

Tested on 1.4.4, 1.5.2 and Edge (fiddle)

Change History

comment:1 follow-up: ↓ 2 Changed 2 years ago by dmethvin

  • Owner set to Thomas
  • Status changed from new to pending

When you say "expected", is there some governing spec for this behavior? Or are you just saying you expected to be able to pass undefined values and have jQuery do something useful with it?

comment:2 in reply to: ↑ 1 Changed 2 years ago by Thomas

  • Status changed from pending to new

Replying to dmethvin:

When you say "expected", is there some governing spec for this behavior? Or are you just saying you expected to be able to pass undefined values and have jQuery do something useful with it?

I was unable to find anything in the $.ajax doc, or in the jquery source by looking quickly.

It was "my" expected behaviour, based on the $.param documentation

Create a serialized representation of an array or object, suitable for use in a URL query string or Ajax request.

Therefore, I assumed the expected behavior would be identical.

comment:3 Changed 2 years ago by dmethvin

  • Status changed from new to pending

I'm inclined to close this wontfix then. How are the properties getting an undefined value?

comment:4 Changed 2 years ago by trac-o-bot

  • Status changed from pending to closed
  • Resolution set to invalid

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

comment:5 Changed 23 months ago by Thomas

Replying to dmethvin:

I'm inclined to close this wontfix then. How are the properties getting an undefined value?

(I'm the original poster)

IIRC the undefined values were computed on clientside, and correct from a application-logic point of view.

Assuming the current behaviour is as expected, I feel "something" is misleading/confusing as $.param "is suitable for use in a URL ...." and has different behaviour than $.ajax.

It just seems inconsistent.

(Oh, and sorry for the very very late followup. )

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.