Browse Source

Made CSRF JavaScript example more reusable.

sdwoodbury 3 years ago
parent
commit
691b8dd8ed
1 changed files with 6 additions and 5 deletions
  1. 6 5
      docs/ref/csrf.txt

+ 6 - 5
docs/ref/csrf.txt

@@ -150,12 +150,13 @@ Finally, you'll need to set the header on your AJAX request. Using the
 
     const request = new Request(
         /* URL */,
-        {headers: {'X-CSRFToken': csrftoken}}
+        {
+            method: 'POST',
+            headers: {'X-CSRFToken': csrftoken},
+            mode: 'same-origin' // Do not send CSRF token to another domain.
+        }
     );
-    fetch(request, {
-        method: 'POST',
-        mode: 'same-origin'  // Do not send CSRF token to another domain.
-    }).then(function(response) {
+    fetch(request).then(function(response) {
         // ...
     });