Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example-javascript-and-fetch.md #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example-javascript-and-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ In order to get our JavaScript working, we first have to enqueue the JavaScript
With that setup in your functions.php you can create an assets/js/api.js file to put your Fetch code for the API Request. This code will handle pulling in your API Requests into JavaScript.

```js
var apiURL = 'http://demo.wp-api.org/wp-json';
var apiRoot = 'http://demo.wp-api.org/wp-json';

// Request latest posts
fetch( apiRoot + '/wp/v2/posts/' )
Expand Down Expand Up @@ -59,4 +59,4 @@ In the first Fetch example we look at pulling in the latest posts via the API.

In both of the examples we start with throwing an error if a Success 200 message is not returned. Then, if successful, we get the response, parse the JSON into native JavaScript and then log it out in the console.

At the very end we catch any errors that may occur if the request does not go through.
At the very end we catch any errors that may occur if the request does not go through.