Answers.Body: <p>You'll need to expose some sort of API that your JavaScript can use to request data from your Craft install.</p>
  <p>There are two first-party options:</p>
  <ol>
  <li><p>Craft CMS has had <a href="https://graphql.org/" rel="nofollow noreferrer">GraphQL</a> support built into core since version 3.3.0. <a href="https://craftcms.com/docs/3.x/graphql.html" rel="nofollow noreferrer">The official docs</a> provides a fairly comprehensive guide to get up and running.</p>
  </li>
  <li><p>If you prefer a RESTful JSON API, the first-party <a href="https://plugins.craftcms.com/element-api?craft3" rel="nofollow noreferrer">Element API plugin</a> provides a simple interface to configure your endpoints. The documentation for Element API can be found <a href="https://github.com/craftcms/element-api" rel="nofollow noreferrer">on the plugin's GitHub page</a>. The Element API plugin is available for both Craft 3 and 4.</p>
  </li>
  </ol>
  <p>Aside from the above, if you happen to use Gatsby for your site there's also a first-party <a href="https://github.com/craftcms/gatsby-source-craft" rel="nofollow noreferrer">Gatsby source plugin</a> for Craft.</p>
  <p>Finally, when using Craft as a CMS for a headless app/site, it's also worth knowing about the <a href="https://craftcms.com/docs/3.x/config/general.html#headlessmode" rel="nofollow noreferrer"><code>headlessMode</code></a>, which &quot;optimizes the system and control panel for headless CMS implementations&quot;.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-16T15:42:46.510Z
Answers.LastActivityDate: 2023-05-16T21:27:27.370Z
Answers.LastEditDate: 2023-05-16T21:27:27.370Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I'm building a static webpage with php and Javascript. I have setup all my data in craft cms entries. I want to use ajax to retrieve the data from craft and just display it on my webpage. How do I do this?</p>
  
Tags: <craft3><php><ajax><vue><js>
Title: How to use ajax call to retrieve data from craft cms entries to use in php application
ThreadText: # How to use ajax call to retrieve data from craft cms entries to use in php application
  
  (Asked by: username_0 on 2023-05-16)
  
  I'm building a static webpage with php and Javascript. I have setup all my data in craft cms entries. I want to use ajax to retrieve the data from craft and just display it on my webpage. How do I do this?
  
  **Tags:** craft3, php, ajax, vue, js
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-05-16. Score: 2 | Accepted answer
  
  You'll need to expose some sort of API that your JavaScript can use to request data from your Craft install.
  
  There are two first-party options:
  
  1. Craft CMS has had [GraphQL](https://graphql.org/) support built into core since version 3.3.0. [The official docs](https://craftcms.com/docs/3.x/graphql.html) provides a fairly comprehensive guide to get up and running.
  2. If you prefer a RESTful JSON API, the first-party [Element API plugin](https://plugins.craftcms.com/element-api?craft3) provides a simple interface to configure your endpoints. The documentation for Element API can be found [on the plugin's GitHub page](https://github.com/craftcms/element-api). The Element API plugin is available for both Craft 3 and 4.
  
  Aside from the above, if you happen to use Gatsby for your site there's also a first-party [Gatsby source plugin](https://github.com/craftcms/gatsby-source-craft) for Craft.
  
  Finally, when using Craft as a CMS for a headless app/site, it's also worth knowing about the [`headlessMode`](https://craftcms.com/docs/3.x/config/general.html#headlessmode), which "optimizes the system and control panel for headless CMS implementations".
  
  
  ---
  
  