Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#11113 closed enhancement (plugin)

Stringify params need to be added before sending them thorugh AJAX

Reported by: InspiredJW <inspired.jw@…> Owned by:
Priority: low Milestone: None
Component: ajax Version: 1.7.1
Keywords: Cc: jaubourg, cowboy, ben_alman
Blocked by: Blocking:

Description

For an example, JavaScript Objects inside of JSON cannot be sent through AJAX.

But it can be solved by stringify the params in AJAX request function.

http://jsfiddle.net/inspired_jw/4Lhef/

I have already pull requested on github and feel sorry for not following the way of developing jQuery.

https://github.com/jquery/jquery/pull/645

Although the order is little bit messed up, I'm trying to add this on ticket here and hope this is recognized and acknowledged as a step of normal jQuery development.

Change History (6)

comment:1 Changed 8 years ago by Rick Waldron

Cc: jaubourg cowboy ben_alman added
Component: unfiledajax
Priority: undecidedlow

cc'ing jaubourg and cowboy on this

Honestly, I think this is completely unnecessary. JSON2 can be conditionally loaded where native JSON is missing.

comment:2 Changed 8 years ago by ajpiano

I also think this is overkill, we have no need internally to be able to serialize objects/arrays to JSON, and if the user knows they need to, they should include JSON2 and prepare their data before sending it via AJAX.

comment:3 in reply to:  2 Changed 8 years ago by InspiredJW <inspired.jw@…>

Replying to ajpiano:

I also think this is overkill, we have no need internally to be able to serialize objects/arrays to JSON, and if the user knows they need to, they should include JSON2 and prepare their data before sending it via AJAX.

I believe that a user should be able to just use AJAX functions intuitively without thinking about stringify JSON objects when they send the data via AJAX. It is surely not a overkill.

comment:4 Changed 8 years ago by timmywil

It is overkill considering that most browsers can handle JSON.stringify natively. If you'd like to stringify JSON across browsers, using JSON2 and setting data oneself is still the best method. Besides, jQuery does not provide any shims (only methods that work across browsers) and the proposed pull would redefine JSON.stringify on every call to jQuery.ajax. Therefore, neither the current pull nor the inclusion of JSON2 itself is really an option. We can wait until jaubourg has seen this to close this ticket, but I imagine he will agree.

comment:5 Changed 8 years ago by cowboy

+1 on the overkill. Including json2.js is the way to do this.

AJAX is not in any way intrinsically linked to the use of JSON, which is just a generic data interchange format that happens to be often used in conjunction with AJAX. On the other hand, GET and POST params are linked to AJAX requests, in that there already exists a well-defined standard for sending additional data to a web server when an HTTP request is made.

While JSON would be my recommended approach for large objects (including a json2.js shim for older browsers), you can use the already-built-in jQuery.param method to convert a data object into GET or POST params for any AJAX request, which most web servers are configured to handle.

http://jsfiddle.net/cowboy/4Lhef/1/

In fact, this method is automatically used by jQuery to serialize params when an object is passed as the "data" parameter in a jQuery AJAX call.

comment:6 Changed 8 years ago by dmethvin

Resolution: plugin
Status: newclosed

I'm not fan either.

Note: See TracTickets for help on using tickets.