2
$("#yes-link").click(function () {
    $.ajax({
        type: "POST",
        url: "http://0.0.0.0:3001/api/helpful/",
        data: {url: "sad", value: "yes"},
        dataType: "jsonp",
        success: function(data) { alert(data); }
    });
 });

For some reason the server is always seeing a GET.

Started GET "/api/helpful/?callback=jQuery11110520667711738497_1405634368646&url=sad&value=yes&_=1405634368649" for 127.0.0.1 at 2014-07-17 18:01:30 -0400
Processing by Api::HelpfulController#get as JSON
Parameters: {
                "callback" = > "jQuery11110520667711738497_1405634368646",
                "url" = > "sad", 
                "value" = > "yes", 
                "_" = > "1405634368649"
                }
  User Load (0.2ms)  SELECT  "users".* FROM "users"  WHERE "users"."ip" = '127.0.0.1' LIMIT 1
  Helpful Load (0.1ms)  SELECT  "helpfuls".* FROM "helpfuls"  WHERE "helpfuls"."user_id" = 1 AND "helpfuls"."url" = 'sad' LIMIT 1
Completed 200 OK in 2ms (Views: 0.1ms | ActiveRecord: 0.3ms

Also, what is that "_"=>"1405634368649" in the parameter list?

halfer
  • 19,824
  • 17
  • 99
  • 186
pitosalas
  • 10,286
  • 12
  • 72
  • 120
  • 2
    JSONP requests aren't really "requests". jQuery creates a ` – Blender Jul 17 '14 at 22:04
  • Yes, but why is it doing a GET instead of the POST that I asked for? And also I wasn't asking about the callback name I was asking about the additional param called "_" – pitosalas Jul 17 '14 at 22:05
  • Because requests that use ` – Sirko Jul 17 '14 at 22:05
  • @pitosalas: It's a cache buster. You can't specify the method with which a browser requests a script because it's always GET. Like I said, this is a bug with jQuery. It shouldn't be sending a request at all. – Blender Jul 17 '14 at 22:06
  • 1
    actually you can't `post` a jsonp, it always is sent as a `get` => http://stackoverflow.com/questions/4508198/how-to-use-type-post-in-jsonp-ajax-call – Amin Jafari Jul 17 '14 at 22:10
  • Thanks, gotcha. The request on the server is properly a post but your saying that if I want to use jsonp through query I am out of luck. – pitosalas Jul 18 '14 at 15:16

0 Answers0