Bug Tracker

Opened 17 years ago

Closed 16 years ago

Last modified 11 years ago

#197 closed feature (invalid)

$.postJSON

Reported by: cdomigan Owned by:
Priority: minor Milestone:
Component: ajax Version:
Keywords: json Cc:
Blocked by: Blocking:

Description

A $.postJSON method would be handy.

Change History (5)

comment:1 Changed 16 years ago by joern

Resolution: invalid
Status: newclosed

If you need this alot, you could just add it as a plugin:

$.postJSON = fuction(url, data, callback) {
	$.post(url, data, callback, "json");
};

This saves about 2 characters per use, not really that very handy...

comment:2 Changed 16 years ago by [email protected]

Any example of it?

comment:3 Changed 16 years ago by [email protected]

Keywords: json added

I've used this script quite successfully: http://www.thomasfrank.se/json_stringify_revisited.html

I have an app that stores data in a JSON object as a user is doing things. In order to get that JS object to the server to do something useful with it, it has to be converted to a string first. "JSONstring.make(myobject)" does just that. It's like Serialize, but for JSON.

I agree it would be useful to have build it, but I don't mind including an external script to do it.

comment:4 Changed 14 years ago by cjwilks

The problem with the workaround suggested by joern is that it doesn't actually enable you to POST (read: send) JSON. It simply allows you to send form data using post, and then receive JSON in return. A true postJSON function would let you send JSON. It would accept a javascript object in the "data" input and automatically:

# serialize it to a string # set the content type to application/json (as specified in RFC 4627)

To actually support this, jquery would need to include a small JSON stringifier.

comment:5 Changed 14 years ago by cjwilks

(Formatting Correction) It would accept a javascript object in the "data" input and automatically:

  1. serialize it to a string
  1. set the content type to application/json (as specified in RFC 4627)
Note: See TracTickets for help on using tickets.