开发者

Sending data throug Ajax and processing them on an action controller

I am trying to send some geolocation data via Ajax and process them on a specific action of a controller.

The code (which is in the view) looks like:

$.ajax({
        type: "GET",
 开发者_如何转开发       url: "/save_location",
        data: "lat=" + position.coords.latitude + "&long=" +  
            position.coords.longitude
});

I have a save_location action which is located in the users controller:

 def save_temp_location
    cookies[:lat] = params[:lat]
    cookies[:long] = params[:long]
 end

I want to save those data temporarily while the user is browsing the site. Inside my view I have tried to display the values of cookies[:lat] and cookies[:long] to check whether it worked or not: Unfortunately, nothing is displayed. I looked at the console the GET request is made (the route is correct):

Started GET "/save_location?lat=48.856666&long=2.350987" for 127.0.0.1 at 2011-05-09 12:02:25 +0100
  Processing by UsersController#save_temp_location as 
  Parameters: {"lat"=>"48.856666", "long"=>"2.350987"}
Redirected to http://fr.localhost.dev:3000/
Completed 302 Found in 1ms

I tried debugging by placing a: puts "foo" or raise "foo" in that action but nothing happens (however I do get the appropriate behaviour when browsing manually to /save_location). Does the 302 http code, have something to do with that? (and what does it mean in this context?).

What do you think is wrong? Am I missing a very important point?

Thanks!


Aren't you be redirected by a filter ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜