0

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;
 }
 });
};
asked Nov 22, 2014 at 18:43
3
  • 4
    It's a bit unclear what you're asking here, really? Commented Nov 22, 2014 at 18:45
  • 1
    It sounds like e.latlng doesn't exist. What happens when you console.log(e.latlng) before doing the $.ajax()? Commented Nov 22, 2014 at 18:56
  • No, it exists, because when I put data: 123, then this alert(e.latlng.lat) gives some coordinates, so I know it exists... Commented Nov 22, 2014 at 19:46

1 Answer 1

2

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)

answered Nov 22, 2014 at 19:37
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.