{"id":158277,"date":"2016-08-19T14:00:00","date_gmt":"2016-08-19T14:00:00","guid":{"rendered":"https:\/\/premium.wpmudev.org\/blog\/?p=158277"},"modified":"2016-10-05T06:02:17","modified_gmt":"2016-10-05T06:02:17","slug":"javascript-ajax","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/javascript-ajax\/","title":{"rendered":"Javascript For WordPress Developers: Using AJAX"},"content":{"rendered":"<p>AJAX, or Asynchronous Javascript and XML, is used to communicate with server-side scripts and allows you to load content dynamically without having to reload the page.<\/p>\n<p>Say, for example, that you&#8217;re building a website for a local charity and you want to encourage a positive vibe. You\u00a0could add a button titled &#8220;Show some love!&#8221; with a counter on the homepage and, thanks to AJAX, every time the button is pressed the counter would increment without reloading the page.<\/p>\n<p>This is the example we&#8217;re going to build in today&#8217;s tutorial.<\/p>\n<p>This is the final post in our five-part series focusing on JavaScript for WordPress developers. Throughout this series, you\u2019ll learn the basics, but I\u2019ll presume you already have a working knowledge of HTML and CSS. If you need help with these building blocks, take a look at our series about <a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-beginners-getting-started\/\" target=\"_blank\">WordPress Development for Beginners<\/a>.<\/p>\n<p>In the past four tutorials, we&#8217;ve looked at the basics of Javascript, jQuery and how to use basic JavaScript in WordPress. In this article, you&#8217;ll learn about what AJAX is, what it can be used for, and how to create cool functionality with it in WordPress.<\/p>\n<p>Let&#8217;s get started.<\/p>\n<p><strong>Missed a tutorial in our JavaScript for WordPress Developers series? You can catch up on all five posts here:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/javascript-wordpress-basics\/\" target=\"_blank\">JavaScript for WordPress Developers: Learning the Basics<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/javascript-wordpress-objects\/\" target=\"_blank\">JavaScript for WordPress Developers: Getting Started With Objects<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/getting-started-jquery\/\" target=\"_blank\">JavaScript for WordPress Developers: Getting Started With jQuery<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/loading-javascript-wordpress\/\" target=\"_blank\">JavaScript for WordPress Developers: Loading JavaScript in WordPress<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/javascript-ajax\/\" target=\"_blank\">Javascript For WordPress Developers: Using AJAX<\/a><\/li>\n<\/ul>\n<h3>Basic AJAX Flow<\/h3>\n<p>A common AJAX flow follows the steps below:<\/p>\n<ol>\n<li>Initiate an AJAX call due to a user action<\/li>\n<li>Receive and process the request on the server<\/li>\n<li>Capture the response and perform any required actions via JavaScript<\/li>\n<\/ol>\n<h4>Setting Up a New Theme Environment<\/h4>\n<p>Let&#8217;s set this up in WordPress. Our first example will show a simple pop-up containing the number of comments a post has when we click on the title. We&#8217;ll use a child theme based on the default Twenty Sixteen WordPress theme so we all start from the same base.<\/p>\n<p>Here&#8217;s what you need to do: Create a new folder in the <strong>themes<\/strong> directory in your WordPress install and name it &#8220;ajax-test.&#8221; Within the directory, create two files: <code>style.css<\/code>, which is required by WordPress, and\u00a0<code>functions.php<\/code>, which we&#8217;ll use to add our own functionality, and finally\u00a0<code>script.js<\/code>, which will contain our JavaScript code. Add the following to the stylesheet:<\/p>\n<div class=\"gist\" data-gist=\"cf925e71ebbb56fe08ceef0acbfb98f4\" data-gist-file=\"style.css\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/cf925e71ebbb56fe08ceef0acbfb98f4.js?file=style.css\">Loading gist cf925e71ebbb56fe08ceef0acbfb98f4<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>The stylesheet from the parent theme needs to be loaded by the child theme. Once upon a time this was done by importing it from the child theme&#8217;s CSS file but the recommended way of achieving it now is by enqueueing it. If you need a refresher on enqueing, have another read over <a href=\"https:\/\/wpmudev.com\/blog\/loading-javascript-wordpress\/\" target=\"_blank\">part four in this series<\/a>.<\/p>\n<p>Let&#8217;s enqueue the parent&#8217;s stylesheet and our JavaScript file in one go:<\/p>\n<div class=\"gist\" data-gist=\"07a5f1a346f6648243fb3c2ee0b5c3c3\" data-gist-file=\"functions.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/07a5f1a346f6648243fb3c2ee0b5c3c3.js?file=functions.php\">Loading gist 07a5f1a346f6648243fb3c2ee0b5c3c3<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>If you feel you have the energy to go one step further, find a nice image, crop it to 880px by 660px and place it in the child theme&#8217;s folder, and then name it it <code>screenshot.png<\/code>. It will show up in the <strong>Appearance<\/strong> section when you&#8217;re ready to activate the theme.<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/08\/select-theme.png\" alt=\"Add an image to your child theme and voila!\" width=\"670\" height=\"325\" \/><figcaption class=\"wp-caption-text\">Add an image to your child theme and voila!<\/figcaption><\/figure>\n<p>Since this child theme is based on Twenty Sixteen and we haven&#8217;t modified anything (yet!), the site should look exactly as if it were running the parent theme.<\/p>\n<h4>Adding a\u00a0Button<\/h4>\n<p>To get started, let&#8217;s add the &#8220;Show some love!&#8221; button. A great place to put it would be the sidebar of posts in the theme.<\/p>\n<p>After some research, it turns out that the sidebar is created by a function named <code>twentysixteen_entry_meta()<\/code> which resides in <code>inc\/template-tags.php<\/code> in the parent theme.<\/p>\n<p>This function is &#8220;pluggable,&#8221; which means that we can modify it by defining it in our own <em>functions.php<\/em> file. The first step of this is to copy-paste the whole function into our own <em>functions.php<\/em> file:<\/p>\n<div class=\"gist\" data-gist=\"ee132d4e746a1e080485659c197c146f\" data-gist-file=\"twenty-sixteen-entry-meta.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ee132d4e746a1e080485659c197c146f.js?file=twenty-sixteen-entry-meta.php\">Loading gist ee132d4e746a1e080485659c197c146f<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Let&#8217;s add our button to the very bottom of all that metadata:<\/p>\n<div class=\"gist\" data-gist=\"91a435be54a57bb5aa32c35e1fd4e395\" data-gist-file=\"basic-button.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/91a435be54a57bb5aa32c35e1fd4e395.js?file=basic-button.php\">Loading gist 91a435be54a57bb5aa32c35e1fd4e395<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Let&#8217;s walkthrough what all that code means.<\/p>\n<p>The first line retrieves the number of loves the post has received. In some cases, this data will not exist, i.e. when no one has clicked the button yet. Due to this, we use the second line in the code to set the value to <code>0<\/code> if the value is empty.<\/p>\n<p>The third line outputs the button, which consists of a span containing an image and the number of loves. I&#8217;ve left the source of the image empty because I want to use an SVG in there. You could use base64 encoded SVG to create an image inline. This saves you requests and will make your website perform better.<\/p>\n<p>I used this free little <a href=\"https:\/\/www.iconfinder.com\/icons\/675969\/favorite_heart_like_love_icon#size=128\" target=\"_blank\">heart image<\/a>, clicking on the <code>SVG - Base64<\/code> link below it. Copy-paste the code you receive into the image source like so:<\/p>\n<div class=\"gist\" data-gist=\"4b5c5be546c3363c174f098aef4e33d8\" data-gist-file=\"button-svg.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/4b5c5be546c3363c174f098aef4e33d8.js?file=button-svg.php\">Loading gist 4b5c5be546c3363c174f098aef4e33d8<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>I also used a little CSS to style the button and give it a hover effect. It&#8217;s not very obvious that this is a button, but it will do for our simple test.<\/p>\n<div class=\"gist\" data-gist=\"968e49b14d4708be1807b346ed2f057e\" data-gist-file=\"button-style.css\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/968e49b14d4708be1807b346ed2f057e.js?file=button-style.css\">Loading gist 968e49b14d4708be1807b346ed2f057e<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/08\/love-button.png\" alt=\"Our little love button, ready to be powered by AJAX.\" width=\"670\" height=\"458\" \/><figcaption class=\"wp-caption-text\">Our little love button, ready to be powered by AJAX.<\/figcaption><\/figure>\n<h4>Triggering an Action<\/h4>\n<p>Finally, we get to our JavaScript! We need to target our button element and detect a click on it. Here&#8217;s how to do it:<\/p>\n<div class=\"gist\" data-gist=\"8e46806ed4057efed8a64dada67a8f26\" data-gist-file=\"action.js\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/8e46806ed4057efed8a64dada67a8f26.js?file=action.js\">Loading gist 8e46806ed4057efed8a64dada67a8f26<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>If you click on the button at this stage you should see a JavaScript alert with the text &#8220;Love is being given.&#8221;<\/p>\n<h4>Data Requirements<\/h4>\n<p>Instead of that text we need to trigger an AJAX call. Before we write our code, let&#8217;s figure out what we need to send.<\/p>\n<p><strong>The AJAX URL<\/strong><\/p>\n<p>First and foremost, we need a place to send the data. The place we send the data to will process the data and respond to the call. WordPress has a location built in to handle AJAX calls, which we can use: the <code>admin-ajax.php<\/code> file within <code>wp-admin<\/code>. We have no way to add this URL to our script (short of hardcoding it, which is out of the question) so we&#8217;ll use some WordPress trickery.<\/p>\n<p>The <code>wp_localize_script()<\/code> function was originally intended to translate strings in JavaScript files, which it does well. We can also use it to pass variables to our JavaScript files, in this case the URL of our AJAX file.<\/p>\n<p>Add the following code to our existing <code>ajax_test_scripts()<\/code> function like so:<\/p>\n<div class=\"gist\" data-gist=\"c2611453b484fbfac93fd3b4875338c7\" data-gist-file=\"localize.js\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/c2611453b484fbfac93fd3b4875338c7.js?file=localize.js\">Loading gist c2611453b484fbfac93fd3b4875338c7<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>The result of this will be an object named <code>ajaxTest<\/code>\u00a0, which will contain the array given in the final parameter as properties. To grab the value of <code>ajax_url<\/code> we can use <code>ajaxTest.ajax_url<\/code> in our JavaScript.<\/p>\n<p><strong>The Post ID<\/strong><\/p>\n<p>We&#8217;ll be sending arbitrary data like the post&#8217;s ID (which we&#8217;ll use to identify the post we&#8217;re adding love to). This can be retrieved from the DOM. Take a look at the structure used in the Twenty Sixteen theme below:<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670 size-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/08\/twenty-sixteen-dom.png\" alt=\"Twenty Sixteen's DOM\" width=\"670\" height=\"273\" \/><figcaption class=\"wp-caption-text\">Twenty Sixteen&#8217;s DOM<\/figcaption><\/figure>\n<p>Our button has an &#8220;article&#8221; element as one of its ancestors. This element has the class <code>post<\/code> and contains the numeric ID in the ID property. While not the most elegant solution we can grab the ID from there.<\/p>\n<div class=\"gist\" data-gist=\"8b567ac1c323030611a6009bdcdeabdf\" data-gist-file=\"get-id.js\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/8b567ac1c323030611a6009bdcdeabdf.js?file=get-id.js\">Loading gist 8b567ac1c323030611a6009bdcdeabdf<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p><strong>The Action<\/strong><\/p>\n<p>WordPress also requires that we send a parameter named action. Since all actions will be sent to <code>admin-ajax<\/code> we need a way to differentiate between them \u2013 this is what this parameter is used for.<\/p>\n<h4>Sending An AJAX Request<\/h4>\n<p>We can now put everything together. We need to create an AJAX call to <code>wp-admin\/admin-ajax.php<\/code> that contains the post ID and an action. Here&#8217;s how.<\/p>\n<div class=\"gist\" data-gist=\"6e4398c91279f21182f75f1d4041852b\" data-gist-file=\"ajax-call.js\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/6e4398c91279f21182f75f1d4041852b.js?file=ajax-call.js\">Loading gist 6e4398c91279f21182f75f1d4041852b<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p><code>$.ajax()<\/code> is the function used which takes a bunch of parameters. <code>url<\/code> contains the target which is currently our website&#8217;s <code>ajax-url.php<\/code> file. The type is set to <code>post<\/code> which should be familiar from HTML forms. The data parameter is an object that contains key-value pairs we want to send to the server. Later on, we&#8217;ll be able to read them with <code>$_POST['action']<\/code> and <code>$_POST['post_id']<\/code>.<\/p>\n<p>The success parameter is a function, which will run when the AJAX call has been completed. We&#8217;ll show a simple alert that shows &#8220;Success! The new count is&#8221; with our response tacked on the end.<\/p>\n\n<h4>Processing the Request<\/h4>\n<p>Normally you would need to edit the <code>admin-ajax.php<\/code> file since the request is sent there. This is a core file though, which means that editing is a big no-no. WordPress allows you to precess AJAX calls using hooks and the action parameter. The pattern is the following:<\/p>\n<p>If you named your action &#8216;add_love&#8217;, you need to attach a function (names anyway you like) to a hook named <code>wp_ajax_add_love<\/code> and\/or <code>wp_ajax_nopriv_add_love<\/code>. The nopriv one fires for logged out users, the one without it fires for logged in users only. In our case we&#8217;d like both. As a quick test, let&#8217;s hard-code a response:<\/p>\n<div class=\"gist\" data-gist=\"c3dd25ffa1cb3da3deb77e767191682c\" data-gist-file=\"ajax.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/c3dd25ffa1cb3da3deb77e767191682c.js?file=ajax.php\">Loading gist c3dd25ffa1cb3da3deb77e767191682c<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>We attached our function to both hooks, echoed <code>4<\/code> and then used the <code>die()<\/code> function. This is required in WordPress, otherwise you will receive a <code>0<\/code> at the end of every response. If you click the button now you should see the following:<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-670x670 size-670x670\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/08\/ajax-button.png\" alt=\"Ajax button popup\" width=\"670\" height=\"278\" \/><figcaption class=\"wp-caption-text\">Ajax button popup<\/figcaption><\/figure>\n<p>To get the actual number of &#8220;loves&#8221; all we need to do is retrieve the current number, increment it by one, save it to the database and echo the new number.<\/p>\n<div class=\"gist\" data-gist=\"d7e20186e817ce416aca57f74304cf49\" data-gist-file=\"ajax-complete.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/d7e20186e817ce416aca57f74304cf49.js?file=ajax-complete.php\">Loading gist d7e20186e817ce416aca57f74304cf49<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>If you click the button now you should see the popup showing you &#8220;1&#8221;. If you refresh the page you should see the new number being shown. Clicking the button will return 2. All we need to do now is make sure the number is reflected in the UI immediately.<\/p>\n<h4>Performing UI Changes Using the Response<\/h4>\n<p>This part seems easy (because it is), but is usually the most difficult to get right \u2013 more on this later. For now all we need to do is pinpoint the element that contains the current number and change its content to the response.<\/p>\n<div class=\"gist\" data-gist=\"c76cb43a43af7846690b7a40ce984363\" data-gist-file=\"response.js\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/c76cb43a43af7846690b7a40ce984363.js?file=response.js\">Loading gist c76cb43a43af7846690b7a40ce984363<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>I&#8217;ve only added two lines to our previous JS code. On line 5, I store the element that contains the number in the <code>$number<\/code> variable. On line 14, I modify the text of this element to contain the response, which is the new love count.<\/p>\n<h3>Additional Concerns<\/h3>\n<p>AJAX isn&#8217;t too difficult on the surface but it gets very difficult when trying to create a nice UI. Sending data, processing it and creating a response is almost trivial but here are some issues regarding the usage of the response that you may not have thought of:<\/p>\n<ul>\n<li>What happens if someone accidentally double-clicks?<\/li>\n<li>What if someone abuses the button and presses it continuously?<\/li>\n<li>If the response takes a long time to arrive the user is left wondering.<\/li>\n<li>The number change may not be too obvious.<\/li>\n<li>The button itself is not obviously a button.<\/li>\n<\/ul>\n<p>Solving these issues is not really within the scope of this tutorial. Some of this\u00a0can be learned reading other tutorials, but you partly need to rely on your experience to create a smooth and understandable UI for your actions.<\/p>\n<p>Safety is another huge concern. In this simple love example it may not be obvious but you might want to build a button for admins that deletes posts. All actions should be protected by <a href=\"https:\/\/codex.wordpress.org\/WordPress_Nonces\" target=\"_blank\">nonces<\/a>.<\/p>\n<h3>WordPress and the Power of AJAX<\/h3>\n<p>Creating smooth interfaces and useful user actions is easy using AJAX. You&#8217;ll need to send a request, which contains some data, process it on the server, send back a response and use the response to initiate UI changes.<\/p>\n<p>The real challenge of AJAX, though, is using it responsibly and making sure that your UI is air-tight before, during and after your action has been performed.<\/p>\n<p>While this is the final tutorial in JavaScript for WordPress Developers, your learning doesn&#8217;t have to stop here! If you would like to continue expanding your JavaScript knowledge, here are some great resources worth checking out:<\/p>\n<ul>\n<li><a href=\"http:\/\/eloquentjavascript.net\/\" target=\"_blank\">Eloquent JavaScript:<\/a><strong>\u00a0<\/strong>Available both digitally and as a hardcopy book, Eloquent JavaScript is a comprehensive and well-structured introduction to JavaScript whether you\u2019re new to the language or you&#8217;re an old hat who&#8217;s looking for a quick way to get up to speed.<\/li>\n<li><a href=\"http:\/\/www.w3schools.com\/js\/\" target=\"_blank\">W3Schools:<\/a>\u00a0It feels like W3Schools has been around forever, and for good reason \u2013 it\u2019s an excellent resource for beginners that\u2019s crammed full of examples. Best of all, you can edit the JavaScript examples on the site live and see the results of your changes on the front-end.<\/li>\n<li><a href=\"https:\/\/www.codecademy.com\/learn\/javascript\" target=\"_blank\">Codecademy:<\/a>\u00a0If you\u2019re an interactive and hands-on learner, popular online code school Codecademy offers a free 10-hour JavaScript course for beginners. It\u2019s divided into eight units that cover concepts including functions, loops, control flow, data structures, and objects. There\u2019s also a final project that involves building a game from scratch \u2013 but you\u2019ll have to upgrade to Codecademy Pro to get access.<\/li>\n<li><a href=\"https:\/\/shamansir.github.io\/JavaScript-Garden\/\" rel=\"noopener\" target=\"_blank\">JavaScript Garden:<\/a> This collection of documentation covers the most quirky parts of the programming language. It offers advice on how to avoid common mistake and subtle bugs, as well as performance issues and bad practices that those new to JavaScript may come across in their learning.<\/li>\n<li><a href=\"http:\/\/code.tutsplus.com\/tutorials\/the-best-way-to-learn-javascript--net-21954\" target=\"_blank\">Envato tuts+:<\/a>\u00a0If you are completely new to JavaScript, don\u2019t know where to start, and need some hand holding, this fantastic article is a great launching pad.<\/li>\n<li><a href=\"http:\/\/jstherightway.org\/#getting-started\" target=\"_blank\">JavaScript The Right Way:\u00a0<\/a>Despite its name, this one-page guide doesn\u2019t offer instructions on the \u201cthe right way\u201d to learn JavaScript, rather it stands as a collection of resources submitted by developers, from information on how to get started and best practices, to tools for testing and frameworks like jQuery and Backbone.js.<\/li>\n<\/ul>\n<p>As with learning any new skill, the more you read and practice, the easier learning will become and the sooner you\u2019ll be proficient in another language.<\/p>\n<p>Good luck with your JavaScript journey!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AJAX, or Asynchronous Javascript and XML, is used to communicate with server-side scripts and allows you to load content dynamically without having to reload the page. Say, for example, that you&#8217;re building a website for a local charity and you want to encourage a positive vibe. You\u00a0could add a button titled &#8220;Show some love!&#8221; with [&hellip;]<\/p>\n","protected":false},"author":344049,"featured_media":158322,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[557],"tags":[1256,505],"tutorials_categories":[],"class_list":["post-158277","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-ajax","tag-javascript"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/158277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/344049"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=158277"}],"version-history":[{"count":11,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/158277\/revisions"}],"predecessor-version":[{"id":159776,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/158277\/revisions\/159776"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/158322"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=158277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=158277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=158277"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=158277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}