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
ivanacorovic
2,8974 gold badges34 silver badges51 bronze badges
-
4It's a bit unclear what you're asking here, really?Henrik Andersson– Henrik Andersson2014年11月22日 18:45:00 +00:00Commented Nov 22, 2014 at 18:45
-
1It sounds like e.latlng doesn't exist. What happens when you console.log(e.latlng) before doing the $.ajax()?7stud– 7stud2014年11月22日 18:56:59 +00:00Commented 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...ivanacorovic– ivanacorovic2014年11月22日 19:46:32 +00:00Commented Nov 22, 2014 at 19:46
1 Answer 1
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
Dbz
2,7614 gold badges36 silver badges53 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-rb