Side navigation
#11113 closed enhancement (plugin)
Opened December 29, 2011 06:08PM UTC
Closed January 11, 2012 04:05PM UTC
Last modified March 14, 2012 09:27AM UTC
Stringify params need to be added before sending them thorugh AJAX
Reported by: | InspiredJW <inspired.jw@gmail.com> | 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.
Attachments (0)
Change History (6)
Changed December 29, 2011 06:58PM UTC by comment:1
cc: | → jaubourg, cowboy, ben_alman |
---|---|
component: | unfiled → ajax |
priority: | undecided → low |
Changed December 29, 2011 07:04PM UTC by comment:2
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.
Changed December 29, 2011 07:49PM UTC by comment:3
Replying to [comment:2 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.
Changed December 29, 2011 09:57PM UTC by comment:4
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.
Changed December 29, 2011 11:00PM UTC by comment:5
+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.
Changed January 11, 2012 04:05PM UTC by comment:6
resolution: | → plugin |
---|---|
status: | new → closed |
I'm not fan either.
cc'ing jaubourg and cowboy on this
Honestly, I think this is completely unnecessary. JSON2 can be conditionally loaded where native JSON is missing.