Problem:
Sign in
Sign out
Sign in (successful 201. However prints WARNING: Can't verify CSRF token authenticity in server logs)
Subsequent ajax request fails 401 unauthorised
Refresh the website (at this point, CSRF in the page header changes to something else)
I can sign in, it works, until I try to sign out and in again.
Solution:
protect_from_forgery :except => :rate
$.ajax({ url: 'YOUR URL HERE',
type: 'POST',
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
data: 'someData=' + someData,
success: function(response) {
$('#someDiv').html(response);
}
});
<%= csrf_meta_tag %>
$(document).ajaxSend(function (e, xhr, options) {
xhr.setRequestHeader("X-CSRF-Token", MyApp.session.get("csrf-token"));
});
signOut: function() {
var params = {
dataType: "json",
type: "GET",
url: this.urlRoot + "/sign_out.json"
};
var self = this;
return $.ajax(params).done(function(data) {
self.set("csrf-token", data.csrfToken);
self.unset("user");
});
}
分享到:
相关推荐
Attach a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event. The XMLHttpRequest and settings used for that request are passed as arguments to the callback. ...
Asynchronous Procedure Calls ,也就是异步过程调用,这份文档是内核中APC的详尽介绍,值得一看
SAPTEC training course
jQuery solves the problems of DOM manipulation, event detection, AJAX calls, element selection and document queries, element attribute and data management, as well as object management utilities....
1 ■ Introducing ASP.NET AJAX 3 2 ■ First steps with the Microsoft Ajax Library 36 3 ■ JavaScript for Ajax developers 73 4 ■ Exploring the Ajax server extensions 114 5 ■ Making asynchronous ...
jQuery solves the problems of DOM manipulation, event detection, AJAX calls, element selection and document queries, element attribute and data management, as well as object management utilities....
Tracing Oracle Internal Calls
前端项目-jquery.iframe-transport,jQuery plugin that implements an iframe transport so that ajax calls support the uploading of files using standard HTML file input fields
jQuery mobile librariesUse Ajax calls for background browser.server communicationAcquire CSS2 & CSS3 skills for professionally styling your web pagesImplement powerful HTML5 features, including ...
ajax调用 Ajax 调用示例 感谢 Tuts 的帮助。 我最喜欢的资源之一。
阅读 《Accurately Profiling Direct3D API Calls (Direct3D 9)》之后,本人做的总结
AsyncCalls(异步调用函数),Delphi异步调用函数的单元和例子
What it calls for is Ajax Hacks from O'Reilly. This valuable guide provides direct, hands-on solutions that take the mystery out of Ajax's many capabilities. Each hack represents a clever way to ...
such as using WebSockets, invoking bean methods directly from Ajax, executing client-side JavaScript when Ajax calls complete, and more Along the way you’ll broaden your knowledge of JSF ...
这东西比你想象的要难找,用的时候,怎么也找不到,闲来放出来
我已经使用Jquery作为客户端框架,这有助于对服务器进行Ajax调用并将json数据加载到网页。 Node.js具有丰富的库函数集合,可以轻松托管服务器。 使用jQuery对服务器进行Ajax调用是一项棘手的任务,并且花费了一些...
1.1 Signalling in GSM 3 1.2 GSM Mobility 3 1.3 Mobile Station 4 1.4 Identifiers in the GSM Network 4 1.4.1 International Mobile Subscriber Identity 4 1.4.2 Mobile Station Integrated Services Digital ...
The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet...