File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ Insert a hidden input field named `csrf_token` in your forms.
52
52
<button type="submit">Send</button>
53
53
</form>
54
54
55
- You can also use following javascript code to perform AJAX calls ( jQuery 1.5 and newer).
55
+ Javascript- code sample to perform AJAX calls with jQuery 1.5 and newer.
56
56
57
57
function csrfSafeMethod(method) {
58
58
// HTTP methods that do not require CSRF protection.
@@ -67,6 +67,24 @@ You can also use following javascript code to perform AJAX calls (jQuery 1.5 and
67
67
}
68
68
});
69
69
70
+ $("#AJAXForm").submit(function(event){
71
+ event.preventDefault();
72
+ $.ajax({
73
+ type: "POST",
74
+ url: "/Hello",
75
+ data: {
76
+ name: $("#AJAXFormName").val()
77
+ },
78
+ success: function(data) {
79
+ // Switch to HTML code returned by server on success.
80
+ jQuery("body").html(data);
81
+ },
82
+ error: function(jqXHR, status, errorThrown) {
83
+ alert(jqXHR.statusText);
84
+ },
85
+ });
86
+ });
87
+
70
88
A demo application is provided in the samples directory. To launch it:
71
89
72
90
revel run github.com/cbonello/revel-csrf/samples/demo
You can’t perform that action at this time.
0 commit comments