[英]Rails4 - How to receive and send JSON data securely through Ajax and store it?
I have a page(like https://www.helloabc.com/han.html ) that is loaded inside an iframe on an app of different domain. 我有一个页面(如https://www.helloabc.com/han.html ),该页面已加载到其他域的应用程序的iframe中。 I added the following to enable loading the page in an iframe to remove the error("Refused to display document because display forbidden by X-Frame-Options").
我添加了以下内容以启用在iframe中加载页面以消除错误(“拒绝显示文档,因为X-Frame-Options禁止显示”)。
config.action_dispatch.default_headers['X-Frame-Options'] = "ALLOW-FROM https://xyz.com"
The iframe page sends data through ajax json to another page as follows . iframe页面通过ajax json将数据发送到另一个页面,如下所示。
$.ajax({
url: 'https://www.helloabc.com/hello',
type: 'POST',
dataType: 'json',
data: {
"url" : hjurl,
"data" : senddatavar
},
success: function(a){
console.log("success");
console.log(a.message);
},
error: function(request, status, error) {
console.log("error");
}
});
I receive 200 ok in my iframe page. 我在iframe页面中收到200 ok。
heroku[router]: at=info method=POST path="/hello" host=www.helloabc.com request_id=ac3ed869-75cc-484f-94ea-65ea2fccbb9e fwd="117.203.154.1" dyno=web.1 connect=3ms service=26ms status=200 bytes=900
app[web.1]: Started POST "/hello" for 117.203.154.1 at 2014-11-07 16:45:29 +0000
app[web.1]: Processing by HomePageController#hellojson as JSON
app[web.1]: Parameters: {"url"=>"https://abc.yupp.com/hs/_/krki5gea", "data"=>{"0"=>{"id"=>"937bacaeb0f928", "person"=>{"id"=>"1984762436", "dName"=>"zzzzz", "image"=>{"url"=>"https://sbc/photo.jpg"}}, }}}
app[web.1]: Completed 200 OK in 2ms (Views: 0.4ms | ActiveRecord: 0.0ms)
I am new to rails. 我是新手。 I don't know how to grab this data and store it.
我不知道如何获取这些数据并将其存储。 And I dont know how to do it the right way.
而且我不知道如何正确地做。
Can anyone please share what is the best practice to send data through ajax securely and store it? 谁能分享通过ajax安全发送数据并存储数据的最佳实践是什么?
I used params in the following controller to get the data and save it in table 我在以下控制器中使用了params来获取数据并将其保存在表中
def hellojson
m = Haout.new
m.url = params["url"]
m.image = params["data"]["0"]["person"]["image"]["url"]
then i used conditions and based on conditions I did m.save and m.update_attributes 然后我使用条件,并根据条件我做了m.save和m.update_attributes
It is secure if https is used 如果使用https是安全的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.