3

Is it possible to POST data to JSONP? Or does all data have to be passed in the querystring as a GET request? any sample code.

thanks

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • Hi Abu, JSONP *cannot* be used for post operations indeed. On a bigger scale it can't even be used as a reliable technology as it's based Javascript emission, which is considered by many as security threat (some hosters won't let you to host webservices which use JSONP). Just out of curiosity - why do you need POST - you can do a 'logical' post by calling get with parameters - say, I can add stuff to the Db and read back its identity no problem. It's not exactly right from the REST ideology point of view, but you know.. –  Nov 15 '11 at 14:56

3 Answers3

6

No, you can't post data to JSONP. JSONP has to be "submitted" as a script tag, and script tags cannot POST information.

Hope this helps.

mattbasta
  • 13,492
  • 9
  • 47
  • 68
0

If you're using jQuery, try $.post()

http://api.jquery.com/jQuery.post/

Edit: More detailed solution here: How to use getJSON, sending data with post method?

Community
  • 1
  • 1
findzen
  • 541
  • 5
  • 13
  • 1
    From that page: "Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol." POSTs do not work cross-domain. – Jason Hall Nov 19 '10 at 00:26
  • POSTs work cross-domain if the browser, framework, server, etc all support CORS. – hippietrail Dec 22 '11 at 08:59
0

Here's an example:

   $.ajax({
        url: ajaxUrl,
        dataType: 'jsonp',
        type: 'GET',
        cache: false,
        success: sCallbackFunction,
        error: eCallbackFunction,
        jsonpCallback: jsonpCallbackFunction,
        data: dataObject
    });
Glen
  • 171
  • 1
  • 6