Bug Tracker

Ticket #197 (closed feature: invalid)

Opened 8 years ago

Last modified 3 years ago

$.postJSON

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

Description

A $.postJSON method would be handy.

Change History

comment:1 Changed 8 years ago by joern

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

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 8 years ago by imran@…

Any example of it?

comment:3 Changed 8 years ago by bryan@…

  • 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 6 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 6 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.