ivanacorovic
ivanacorovic

Reputation: 2867

How to pass a variable to Ruby through Ajax?

I have this code and it won't work unless I pass a constant to data. What am I doing wrong?

function onMapClick(e) {
  $.ajax({
    url: "/temps",
    type: "POST",
    data: {coordinates: e.latlng},
    success: function(response) {
      // map.openPopup("hello", e.latlon);
      alert(e.latlng.lat);
      // return response;
    }
  });
};

Upvotes: 0

Views: 112

Answers (1)

Dbz
Dbz

Reputation: 2761

Try using toJSON to turn the data into a json string, then when you receive it in your ruby code you can use JSON.parse(data)

Upvotes: 2

Related Questions