Skip to content

Commit aaa6c5e

Browse files
authored
Merge pull request rails#52976 from maciej-ka/docs-api-app-update-jquery-example-to-fetch
docs: update jQuery ajax to fetch in api app guide
2 parents 19ab2b8 + 4cf1314 commit aaa6c5e

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

guides/source/api_app.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,14 @@ format and make them available in your controller inside `params`.
412412
To use this, your client will need to make a request with JSON-encoded parameters
413413
and specify the `Content-Type` as `application/json`.
414414

415-
Here's an example in jQuery:
415+
Here's an example:
416416

417417
```js
418-
jQuery.ajax({
419-
type: 'POST',
420-
url: '/people',
421-
dataType: 'json',
422-
contentType: 'application/json',
423-
data: JSON.stringify({ person: { firstName: "Yehuda", lastName: "Katz" } }),
424-
success: function(json) { }
425-
});
418+
fetch('/people', {
419+
method: 'POST',
420+
headers: { 'Content-Type': 'application/json' },
421+
body: JSON.stringify({ person: { firstName: 'Yehuda', lastName: 'Katz' } })
422+
}).then(response => response.json())
426423
```
427424

428425
`ActionDispatch::Request` will see the `Content-Type` and your parameters

0 commit comments

Comments
 (0)