<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Ajax - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Ajax - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 18 May 2026 16:21:57 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/ajax/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ AJAX Tutorial: What AJAX Is and How to Use it ]]>
                </title>
                <description>
                    <![CDATA[ What is AJAX? AJAX stands for Asynchronous JavaScript And XML. It is not a programming language. It is a technology for developing better, faster and interactive Web Applications using HTML, CSS, JavaScript and XML. HTML : Hypertext Markup Language ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/ajax-tutorial/</link>
                <guid isPermaLink="false">66c343a90bafa8455505c671</guid>
                
                    <category>
                        <![CDATA[ Ajax ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 22 Feb 2020 17:37:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9c72740569d1a4ca3245.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-what-is-ajax"><strong>What is AJAX?</strong></h2>
<p><strong>AJAX</strong> stands for <strong>Asynchronous JavaScript And XML</strong>. It is not a programming language. It is a technology for developing better, faster and interactive Web Applications using HTML, CSS, JavaScript and XML.</p>
<ol>
<li>HTML : Hypertext Markup Language (HTML) is used for defining the structure of a Web Application.</li>
<li>CSS : Cascading Style Sheet (CSS) is used to provide look and style to a Web Application.</li>
<li>JavaScript : JavaScript is used for making a Web Application interactive, interesting and user friendly.</li>
<li>XML : Extensible Markup Language (XML) is a format to store and transport data from the Web Server.</li>
</ol>
<h3 id="heading-whats-the-meaning-of-asynchronous-in-ajax">What's the meaning of Asynchronous in AJAX?</h3>
<p>Asynchronous means that the the Web Application could send and receive data from the Web Server without refreshing the page. This background process of sending and receiving data from the server along with updating different sections of a web page defines Asynchronous property/feature of AJAX.</p>
<h2 id="heading-how-ajax-works">How AJAX works</h2>
<p>AJAX makes use of a browser built-in <strong>XMLHttpRequest object</strong> to request data from a Web Server and <strong>HTML DOM</strong> to display or use the data.</p>
<p><strong>XMLHttpRequest Object</strong> : It is an API in the form an object whose methods help in transfer of data between a web browser and a web server.</p>
<p><strong>HTML DOM</strong> : When a web page is loaded, the browser creates a Document Object Model of the page.</p>
<p><img src="https://i.imgur.com/pfC7QFH.png" alt="Image" width="528" height="395" loading="lazy"></p>
<p><strong>Create a XMLHttpRequest Object :</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> xhttp = <span class="hljs-keyword">new</span> XMLHttpRequest();
</code></pre>
<p><strong>Properties of XMLHttpRequest object :</strong></p>
<p><code>readystate</code> is a property of the XMLHttpRequest Object which holds the status of the XMLHttpRequest.</p>
<ul>
<li>0: request not initialized</li>
<li>1: server connection established</li>
<li>2: request received</li>
<li>3: processing request</li>
<li>4: request finished and response is ready</li>
</ul>
<p><code>onreadystatechange</code> is a property of the XMLHttpRequest Object which defines a function to be called when the readyState property changes.<br><code>status</code> is a property of the XMLHttpRequest Object which returns the status-number of a request</p>
<ul>
<li>200: "OK"</li>
<li>403: "Forbidden"</li>
<li>404: "Not Found"</li>
</ul>
<p><strong>XMLHttpRequest Object Methods :</strong> To send a request to a Web Server, we use the open() and send() methods of the XMLHttpRequest object.</p>
<pre><code class="lang-javascript">xhttp.open(<span class="hljs-string">"GET"</span>, <span class="hljs-string">"content.txt"</span>, <span class="hljs-literal">true</span>);
xhttp.send();
</code></pre>
<p><strong>Create a function changeContent() using JavaScript :</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">changeContent</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> xhttp = <span class="hljs-keyword">new</span> XMLHttpRequest();
  xhttp.onreadystatechange = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.readyState == <span class="hljs-number">4</span> &amp;&amp; <span class="hljs-built_in">this</span>.status == <span class="hljs-number">200</span>) {
     <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"foo"</span>).innerHTML = <span class="hljs-built_in">this</span>.responseText;
    }
  };
  xhttp.open(<span class="hljs-string">"GET"</span>, <span class="hljs-string">"content.txt"</span>, <span class="hljs-literal">true</span>);
  xhttp.send();
}
</code></pre>
<p><strong>AJAX example to change content of a web page :</strong></p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"foo"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>The XMLHttpRequest Object<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"changeContent()"</span>&gt;</span>Change Content<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">changeContent</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> xhttp = <span class="hljs-keyword">new</span> XMLHttpRequest();
  xhttp.onreadystatechange = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.readyState == <span class="hljs-number">4</span> &amp;&amp; <span class="hljs-built_in">this</span>.status == <span class="hljs-number">200</span>) {
      <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"foo"</span>).innerHTML =
      <span class="hljs-built_in">this</span>.responseText;
    }
  };
  xhttp.open(<span class="hljs-string">"GET"</span>, <span class="hljs-string">"content.txt"</span>, <span class="hljs-literal">true</span>);
  xhttp.send();
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The file <code>content.txt</code> should be present in the root directory of the Web Application.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ JQuery Ajax POST Method ]]>
                </title>
                <description>
                    <![CDATA[ Sends an asynchronous http POST request to load data from the server. Its general form is: jQuery.post( url [, data ] [, success ] [, dataType ] ) url : is the only mandatory parameter. This string contains the adress to which to send the request. ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/jquery-ajax-post-method/</link>
                <guid isPermaLink="false">66c35942cf1314a450f0d701</guid>
                
                    <category>
                        <![CDATA[ Ajax ]]>
                    </category>
                
                    <category>
                        <![CDATA[ jQuery ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 10 Dec 2019 23:43:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9ec8740569d1a4ca3f16.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Sends an asynchronous http POST request to load data from the server. Its general form is:</p>
<pre><code class="lang-javascript">jQuery.post( url [, data ] [, success ] [, dataType ] )
</code></pre>
<ul>
<li>url : is the only mandatory parameter. This string contains the adress to which to send the request. The returned data will be ignored if no other parameter is specified</li>
<li>data : A plain object or string that is sent to the server with the request.</li>
<li>success : A callback function that is executed if the request succeeds.it takes as an argument the returned data. It is also passed the text status of the response.</li>
<li>dataType : The type of data expected from the server. The default is Intelligent Guess (xml, json, script, text, html). if this parameter is provided, then the success callback must be provided as well.</li>
</ul>
<h4 id="heading-examples"><strong>Examples</strong></h4>
<pre><code class="lang-javascript">$.post(<span class="hljs-string">'http://example.com/form.php'</span>, {<span class="hljs-attr">category</span>:<span class="hljs-string">'client'</span>, <span class="hljs-attr">type</span>:<span class="hljs-string">'premium'</span>});
</code></pre>
<p>requests <code>form.php</code> from the server, sending additional data and ignoring the returned result</p>
<pre><code class="lang-javascript">$.post(<span class="hljs-string">'http://example.com/form.php'</span>, {<span class="hljs-attr">category</span>:<span class="hljs-string">'client'</span>, <span class="hljs-attr">type</span>:<span class="hljs-string">'premium'</span>}, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">response</span>)</span>{ 
      alert(<span class="hljs-string">"success"</span>);
      $(<span class="hljs-string">"#mypar"</span>).html(response.amount);
});
</code></pre>
<p>requests <code>form.php</code> from the server, sending additional data and handling the returned response (json format). This example can be written in this format:</p>
<pre><code class="lang-javascript">$.post(<span class="hljs-string">'http://example.com/form.php'</span>, {<span class="hljs-attr">category</span>:<span class="hljs-string">'client'</span>, <span class="hljs-attr">type</span>:<span class="hljs-string">'premium'</span>}).done(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">response</span>)</span>{
      alert(<span class="hljs-string">"success"</span>);
      $(<span class="hljs-string">"#mypar"</span>).html(response.amount);
});
</code></pre>
<p>The following example posts a form using Ajax and put results in a div</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!doctype <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>jQuery.post demo<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://code.jquery.com/jquery-1.10.2.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"/"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"searchForm"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"s"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Search..."</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Search"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
<span class="hljs-comment">&lt;!-- the result of the search will be rendered inside this div --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"result"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-comment">// Attach a submit handler to the form</span>
$( <span class="hljs-string">"#searchForm"</span> ).submit(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"> event </span>) </span>{

  <span class="hljs-comment">// Stop form from submitting normally</span>
  event.preventDefault();

  <span class="hljs-comment">// Get some values from elements on the page:</span>
  <span class="hljs-keyword">var</span> $form = $( <span class="hljs-built_in">this</span> ),
    term = $form.find( <span class="hljs-string">"input[name='s']"</span> ).val(),
    url = $form.attr( <span class="hljs-string">"action"</span> );

  <span class="hljs-comment">// Send the data using post</span>
  <span class="hljs-keyword">var</span> posting = $.post( url, { <span class="hljs-attr">s</span>: term } );

  <span class="hljs-comment">// Put the results in a div</span>
  posting.done(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"> data </span>) </span>{
    <span class="hljs-keyword">var</span> content = $( data ).find( <span class="hljs-string">"#content"</span> );
    $( <span class="hljs-string">"#result"</span> ).empty().append( content );
  });
});
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The following example use the github api to fetch the list of repositories of a user using jQuery.ajax() and put results in a div</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!doctype <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>jQuery Get demo<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://code.jquery.com/jquery-1.10.2.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"userForm"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter gitHub User name"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Search"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
<span class="hljs-comment">&lt;!-- the result of the search will be rendered inside this div --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"result"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-comment">// Attach a submit handler to the form</span>
$( <span class="hljs-string">"#userForm"</span> ).submit(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"> event </span>) </span>{

  <span class="hljs-comment">// Stop form from submitting normally</span>
  event.preventDefault();

  <span class="hljs-comment">// Get some values from elements on the page:</span>
  <span class="hljs-keyword">var</span> $form = $( <span class="hljs-built_in">this</span> ),
    username = $form.find( <span class="hljs-string">"input[name='username']"</span> ).val(),
    url = <span class="hljs-string">"https://api.github.com/users/"</span>+username+<span class="hljs-string">"/repos"</span>;

  <span class="hljs-comment">// Send the data using post</span>
  <span class="hljs-keyword">var</span> posting = $.post( url, { <span class="hljs-attr">s</span>: term } );

  <span class="hljs-comment">//Ajax Function to send a get request</span>
  $.ajax({
    <span class="hljs-attr">type</span>: <span class="hljs-string">"GET"</span>,
    <span class="hljs-attr">url</span>: url,
    <span class="hljs-attr">dataType</span>:<span class="hljs-string">"jsonp"</span>
    <span class="hljs-attr">success</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">response</span>)</span>{
        <span class="hljs-comment">//if request if made successfully then the response represent the data</span>

        $( <span class="hljs-string">"#result"</span> ).empty().append( response );
    }
  });

});
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-jqueryajax"><strong>jQuery.ajax()</strong></h3>
<p><code>$.post( url [, data ] [, success ] [, dataType ] )</code> is a shorthand Ajax function, equivalent to:</p>
<pre><code class="lang-javascript">$.ajax({
  <span class="hljs-attr">type</span>: <span class="hljs-string">"POST"</span>,
  <span class="hljs-attr">url</span>: url,
  <span class="hljs-attr">data</span>: data,
  <span class="hljs-attr">success</span>: success,
  <span class="hljs-attr">dataType</span>: dataType
});
</code></pre>
<p><code>$.ajax()</code> provides way more options that can be found <a target="_blank" href="http://api.jquery.com/jquery.ajax/">here</a></p>
<h4 id="heading-more-information"><strong>More Information:</strong></h4>
<p>For more information, please visit the <a target="_blank" href="https://api.jquery.com/jquery.post/">official website</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ REST API cURL Post Request via Construct 3 GameDev Tool & AJAX Module ]]>
                </title>
                <description>
                    <![CDATA[ By Andreas Lopez Hello FreeCodeCamp Reader Community! This Tutorial is made as a little thought experiment but might have some merit for the one or other person. Please keep in mind that this plugin is making an example by adding a product via Const... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/rest-api-curl-post-request-via-construct-3-gamedev-tool-ajax-module/</link>
                <guid isPermaLink="false">66d45d99d62e921b49e02cb6</guid>
                
                    <category>
                        <![CDATA[ construct 3 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ajax ]]>
                    </category>
                
                    <category>
                        <![CDATA[ curl ]]>
                    </category>
                
                    <category>
                        <![CDATA[ json ]]>
                    </category>
                
                    <category>
                        <![CDATA[ REST API ]]>
                    </category>
                
                    <category>
                        <![CDATA[ woocommerce ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WordPress ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 23 Jun 2019 02:25:54 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/c3-woo-wp-banner.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Andreas Lopez</p>
<p>Hello FreeCodeCamp Reader Community! This Tutorial is made as a little thought experiment but might have some merit for the one or other person.</p>
<blockquote>
<p>Please keep in mind that this plugin is making an example by adding a product via Construct 3 Forms + REST API cURL Request to an existing WordPress + WooCommerce installation.</p>
</blockquote>
<p>The principles still are valid for other purposes you might have with the REST API, and I included the .c3p on the bottom of this tutorial. There are more elegant ways about feeding the arrays of information to the application, but this is a quick demo as proof-of-concept that I put together within 2 hours and felt like sharing it due to the lack of API and AJAX information for Construct 3.</p>
<p><strong>Here is the entire code in a single screenshot:</strong></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/c3-api-example.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Construct 3 Source Code Screenshot</em></p>
<h1 id="heading-the-code-broken-down-once-we-click-on-create-product-button">The Code Broken Down once we click on 'Create Product' button</h1>
<ul>
<li>productjson is an obligatory text field outside of the viewport on the layout.</li>
<li>productjson contains our entire payload data pre-formatted as json to allow the REST API to work properly.</li>
<li>The payload contains dynamically created content which are the forms in the layout such as product name, sku, price, etc.</li>
<li>The AJAX module that I renamed AJAX_Data will set the Request_Header to "Content-Type" with the value of "application/json", because the REST API via cURL request will utilize JSON.</li>
<li>The next AJAX_Data with the 'Post to URL' request will be our actual API request.</li>
<li>The Tag is merely a name which can be utilized for example to return the values of the request, in the example of my project - as debugging information.</li>
<li>The URL will start with your domain, i.e. 'https://www.example.com' The next part of the URL is the API request you would like to make, in our example as per WooCommerce documentation to add a product we need '/wp-json/wc/v3/products?'</li>
<li>Last but not least for the URL we need the consumer key and secret in this manner: 'consumer_key=&amp;consumer_secret='</li>
<li>The full URL looks like this: "https://www.example.com/wp-json/wc/v3/products?consumer_key=&amp;consumer_secret="</li>
<li>Next up is the Data. This is simple since we already have made a text box for this exact purpose. Simply refer to it here, in my example the Data will be 'productjson.Text'.</li>
<li>And at the very end, what type of Request. Since we are creating a product we will need 'POST', if we were to retrieve a product we would want a 'GET' request, see the respective documentation of the API you are using.</li>
</ul>
<h3 id="heading-c3p-file-download">.c3p File Download:</h3>
<p><a target="_blank" href="https://drive.google.com/open?id=16DKq5RJD5tCw57oZPruGk_mtTIAe-Um9%5B/url%5D">https://drive.google.com/open?id=16DKq5RJD5tCw57oZPruGk_mtTIAe-Um9</a></p>
<h1 id="heading-requirements-for-my-c3p-example">Requirements for my .c3p example</h1>
<ul>
<li>WordPress Installation with WooCommerce installed</li>
<li>REST API enabled and issued a consumer secret &amp; key</li>
<li>Replace my API secret and key example in the code</li>
<li>Uploaded an image in the media gallery within WordPress</li>
<li>Created a Product Category within WordPress/WooCommerce</li>
</ul>
<p>If you need a free WordPress environment to play around with, I used <a target="_blank" href="https://pantheon.io">https://pantheon.io</a>, under the free plan you can get 2 sandbox sites. Just make sure to install the WP-CORS plugin first and set allowed sites to '*' as seen in their documentation here:<br><a target="_blank" href="https://pantheon.io/docs/platform-considerations/#cors%5B/url%5D">https://pantheon.io/docs/platform-considerations/#cors</a></p>
<p><a target="_blank" href="https://wordpress.org/plugins/wp-cors/%5B/url%5D">https://wordpress.org/plugins/wp-cors/</a></p>
<h3 id="heading-api-source-information-amp-relevant-c3-documentation">API Source Information &amp; Relevant C3 Documentation:</h3>
<p><a target="_blank" href="https://woocommerce.github.io/woocommerce-rest-api-docs">WooCommerce REST API Documentation</a><br><a target="_blank" href="https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/ajax">Construct 3 AJAX Documentation</a><br><a target="_blank" href="https://jsonlint.com/">JSON Validator tool to verify if your JSON is properly formatted.</a><br><a target="_blank" href="https://www.construct.net/en/tutorials/rest-api-curl-post-request-2245">Original Tutorial I wrote on Construct.net</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
