Giter Club home page Giter Club logo

Comments (3)

Krinkle avatar Krinkle commented on August 31, 2024

From coolaj86 on January 21, 2010 12:48:47

There's a jquery.cors plugin which I'm working on which also relies on jquery.json
and I have that method in there.

If you'd like to help, let me know.

from jquery-json.

Krinkle avatar Krinkle commented on August 31, 2024

From krinklemail on September 17, 2011 18:08:19

I'm not sure what the purpose of this function is intended to be.

jQuery has $.getJSON, which takes (url, data, success) and it makes a GET request to 'url' with data (which is an object, translated to a querystring like foo=bar&lorem=ipsum) and it parses the return value of the server (not the sending value of the client) as JSON and passes the parsed object into the success callback function.

A function named postJSON, in my opinion, would make a similar request but as POST, parsing the server return as JSON, not sending JSON to the server.

This seems a bit out of the scope of this plugin in my opinion. You could request the following to be added to jQuery though, in which case you can send JSON to the server in POST like this:

  // in jQuery core
  $.postJSON = function( url, data, callback ) {
    return jQuery.get( url, data, callback, "json" );
  }

  // In your application
  $.postJSON( 'awesome.php', { data: $.toJSON( ... ), function( response ) { ... } );

Status: WontFix

from jquery-json.

Krinkle avatar Krinkle commented on August 31, 2024

From benjamin.schweizer on September 18, 2011 03:09:38

From the reference implementation ( http://json.org/JSONRequest.html ):
"JSONRequest.post does an HTTP POST of a the serialization of a JavaScript object or array, gets the response, and parses the response into a JavaScript value. If the parse is successful, it returns the value to the requesting script. In making the request, no HTTP authentication or cookies are sent. Any cookies returned by the server cause the request to fail. The JSONRequest service can only be used to send and receive JSON-encoded values. JSONRequest cannot be used to retrieve other text formats."

From there, the proposed $.postJSON() function looks consistent to me, but it depends on a 3rd party library like jquery-json (or json2.js) to do the json encoding.

from jquery-json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.