ElementAPI - Can I use javascript/ajax to load json Probably a dumb question, but since i wasn't sure while reading on github, i'll ask here.

I am wondering if I can reach the JSON I created with an URL or is it only for use in PHP?

I would like to load entries from craft from a json with ajax when i click on a button and i wasn't sure if it was possible with this plugin since there is no exemple.

Anybody can help me?

Thanks!
Totally do-able.

Once you have the ElementAPI plugin downloaded and installed, you'll want to make sure you have created a file called elementapi.php and it is in your /craft/config/ directory.

For simplicity's sake, I've used a stripped down version of the example on the github page.

elementapi.php

&lt;?php
namespace Craft;

return [
    'endpoints' =&gt; [
        'news.json' =&gt; [
            'elementType' =&gt; 'Entry',
            'criteria' =&gt; ['section' =&gt; 'news'],
            'transformer' =&gt; function (EntryModel $entry) {
                return [
                    'title' =&gt; $entry-&gt;title,
                    'url' =&gt; $entry-&gt;url,
                    'jsonUrl' =&gt; UrlHelper::getUrl("news/{$entry-&gt;id}.json")
                ];
            },
        ]
    ]
];


Going back to your /craft/config/ directory, you will want to enable CSRF protection..

Finally, (again for simplicity) here is an example of getting my news entries via ajax on docReay

_layout.html

&lt;head&gt;
...
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"&gt;  &lt;/script&gt;
&lt;script&gt;
    $(function () {
        var data = {
            'CSRF': $('input[name="CSRF"]').val(),
        };

        $.ajax({
            'type': 'get',
            'contentType': 'application/x-www-form-urlencoded; charset=UTF-8',
            'cache': false,
            'data': data,
            'url': 'news.json',
            'dataType': 'json',
            'timeout': 50000
        }).done(function (response) {
            console.log(response);
        }).fail(function (error) {
                // Total fail.
            });
        });
    &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="container"&gt;
    {{ getCsrfInput() }}
...


Then if you look at your console, you should see something like this:

{"data":[{"title":"We just installed Craft!","url":"http:\/\/craftsandbox.dev\/news\/2016\/we-just-installed-craft","jsonUrl":"http:\/\/craftsandbox.dev\/news\/3.json"}],"meta":{"pagination":{"total":1,"count":1,"per_page":100,"current_page":1,"total_pages":1,"links":[]}}}


Hope this helps!