Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#9059 closed bug (invalid)

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:
Blocked by: Blocking:

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 (5)

comment:1 Changed 9 years ago by dmethvin

Owner: set to Thomas
Status: newpending

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 9 years ago by Thomas

Status: pendingnew

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 9 years ago by dmethvin

Status: newpending

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

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

Resolution: invalid
Status: pendingclosed

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 8 years 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. )

Note: See TracTickets for help on using tickets.