Hello all,

I'm trying to send some json data from the browser to the server using
prototype without success. On the server side ActiveSupport::JSON.decode
isn't decoding the data.

Here is the code:

Javacript:
<a href="#" onclick='send();return false;'>click</a>
<script>
function send() {

var send_data_url = "/pages/change";
var json_parameters = $H({name: 'Violet', occupation: 'character', age:
25 }).toJSON();

new Ajax.Request(send_data_url, {
  method: 'post',
  parameters: json_parameters,
  contentType: 'application/json;'
});

}

Rails:

def change()
debugger
my_json = ActiveSupport::JSON.decode(params["_json"])
render :text => my_json
end

I've checked with the debugger that the json data that is sent to the
server is the following:
{"_json"=>"%7B%22name%22%3A%20%22Violet%22%2C%20%22occupation%22%3A%20%22charact
er%22%2C%20%22age%22%3A%2025%7D", "action"=>"change",
"controller"=>"pages"}

Can anyone help me?

Thanks.
Best regards,
Migrate
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to