<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: William Rågstad</title>
    <description>The latest articles on DEV Community by William Rågstad (@williamragstad).</description>
    <link>https://dev.to/williamragstad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F129062%2F454849c9-e31c-41b0-b1af-860c72789317.jpeg</url>
      <title>DEV Community: William Rågstad</title>
      <link>https://dev.to/williamragstad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/williamragstad"/>
    <language>en</language>
    <item>
      <title>Write a language in a week - Theory</title>
      <dc:creator>William Rågstad</dc:creator>
      <pubDate>Wed, 06 Apr 2022 08:28:00 +0000</pubDate>
      <link>https://dev.to/williamragstad/write-a-language-in-a-week-theory-2hkg</link>
      <guid>https://dev.to/williamragstad/write-a-language-in-a-week-theory-2hkg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Warning! This article is still under construction!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To fully understand something, one must ask &lt;em&gt;why&lt;/em&gt; until the most fundamental concepts unfolds.&lt;br&gt;
Let's start with the most basic question.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a programming language?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A programming language is a formal language used by humans to write computer programs, consisting of a set of rules that define the structure. In addition to the languages themselves, a &lt;strong&gt;compiler&lt;/strong&gt; is used to convert the program written in the language into a form that can be executed by a computer (a machine), or directly evaluated by an &lt;strong&gt;interpreter&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From the information given above, we can deduce that a programming language is simply the structural rules of the programs.&lt;br&gt;
Like natural languages such as English, German, French, Spanish, etc., many programming languages share similar syntax and semantics, and use English as the base language for keywords and identifiers.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://dev.to/williamragstad/write-a-language-in-a-week-introduction-2el6"&gt;&amp;lt; Previous chapter&lt;/a&gt; | &lt;strong&gt;Chapter 1&lt;/strong&gt; | &lt;em&gt;Next chapter coming soon!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>challenge</category>
      <category>writing</category>
      <category>programming</category>
      <category>language</category>
    </item>
    <item>
      <title>Write a language in a week - Introduction</title>
      <dc:creator>William Rågstad</dc:creator>
      <pubDate>Wed, 06 Apr 2022 08:13:42 +0000</pubDate>
      <link>https://dev.to/williamragstad/write-a-language-in-a-week-introduction-2el6</link>
      <guid>https://dev.to/williamragstad/write-a-language-in-a-week-introduction-2el6</guid>
      <description>&lt;p&gt;In this short series, together we will implement a programming language in just one week. This is a challenge for all developers out there who are interested in developing their skills and gaining a deeper understanding of the general principles on which programming languages are based.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I truly believe that every programmer should at least have tried to write their own little toy language in their career, if not just because it's an incredibly creative and fun experience!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will start with the basics, theory and glue for the whole project. It is important to obtain a good understanding of the goal, methods and techniques before actually implementing anything in code.&lt;/p&gt;

&lt;p&gt;All code will be written in Python, this may be a somewhat controversial choice, but will in my opinion get general concepts and ideas across with much less friction. So, all knowledge gained from these tutorials will be easily transferable and you should not be hindered by unfamiliar syntax.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;So what's the point of all this?&lt;br&gt;
My hope is to share some knowledge and encourage fellow interested developers to take interest in programming language design, as well as having a good time in the process.&lt;br&gt;
If this series results in a couple of new languages somewhere on the web, I'd be extremely happy and would love to see your progress!&lt;/p&gt;

&lt;p&gt;Writing your own programming language will even strengthen your resume and be a great addition to your portfolio.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do we need more languages?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Yes!&lt;/strong&gt;&lt;br&gt;
Or, well… Not in the sense you might think.&lt;br&gt;
So there are more than enough popular general purpose programming languages out there, each with its own twist on things.&lt;br&gt;
But that is not the goal here, the scope of this effort is to build something small that only you or a friend would care about and appreciate. With this methodology we can build something that we will be proud of ourselves. And if others happen to discover our little corner of the universe and get interested, share that experience with them!&lt;/p&gt;

&lt;h2&gt;
  
  
  Who am I?
&lt;/h2&gt;

&lt;p&gt;Glad you asked! Why should I sit here and tell you what to do and what not? Great question.&lt;br&gt;
My name is William, and I am currently studying computer science at &lt;a href="https://en.wikipedia.org/wiki/KTH_Royal_Institute_of_Technology"&gt;KTH&lt;/a&gt; here in Sweden. I have been interested in language design since 2016 and have developed a handful of my own scripting (interpreted) and compiled languages. One of the most prominent examples is &lt;a href="https://lento-lang.org/"&gt;Lento&lt;/a&gt;, which is a functional general-purpose programming language that I have been working on since the end of 2020.&lt;/p&gt;

&lt;p&gt;I am currently working on my final dissertation in a research project together with a number of PhD doctoral students, developing a meta-language system for creating embedded domain-specific and general-purpose languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Release schedule
&lt;/h2&gt;

&lt;p&gt;The idea is that I will work on and continue writing articles about every two weeks, and release them when they are refined and ready.&lt;br&gt;
Of course, many of you will have constructive feedback, tips and ideas that I will read and consider for the upcoming parts, or even edit existing articles to improve and clarify sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Source code
&lt;/h2&gt;

&lt;p&gt;All code and examples can be found on the official mini-lang GitHub repository.&lt;br&gt;
&lt;a href="https://github.com/WilliamRagstad/mini-lang"&gt;https://github.com/WilliamRagstad/mini-lang&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Share your experience!
&lt;/h2&gt;

&lt;p&gt;Sharing knowledge is one of the greatest abilities of mankind.&lt;br&gt;
Use the tags &lt;strong&gt;#WAL&lt;/strong&gt; (Write a language) or &lt;strong&gt;#WAL-W&lt;/strong&gt; (-in one week) when referring to these articles.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  Let's get started with the series and build ourselves a language!
&lt;/h4&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;Chapter 0&lt;/strong&gt; | &lt;a href="https://dev.to/williamragstad/write-a-language-in-a-week-theory-2hkg"&gt;Next chapter &amp;gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>challenge</category>
      <category>writing</category>
      <category>programming</category>
      <category>language</category>
    </item>
    <item>
      <title>How to use $.ajax()</title>
      <dc:creator>William Rågstad</dc:creator>
      <pubDate>Sat, 19 Jan 2019 19:36:37 +0000</pubDate>
      <link>https://dev.to/williamragstad/how-to-use-ajax-3b5e</link>
      <guid>https://dev.to/williamragstad/how-to-use-ajax-3b5e</guid>
      <description>&lt;h2&gt;
  
  
  What is Ajax?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  Important!
&lt;/h4&gt;

&lt;p&gt;When I talk about Ajax in this article, I most often refer to the methods built into JQuery. Please note that Ajax in JQuery &lt;strong&gt;&lt;em&gt;is&lt;/em&gt;&lt;/strong&gt; a type of Ajax, but Ajax &lt;strong&gt;&lt;em&gt;is not&lt;/em&gt;&lt;/strong&gt; the Ajax in JQuery.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ajax is a method to send and receive data from servers, API:s or other web pages and have become a standard when communicating at the web.&lt;/p&gt;

&lt;p&gt;It is not built in to vanilla JavaScript and therefore you'll need to use a library like &lt;a href="https://jquery.com/" rel="noopener noreferrer"&gt;JQuery&lt;/a&gt; &lt;em&gt;(for example)&lt;/em&gt; to get going with Ajax. The name is short for &lt;strong&gt;A&lt;/strong&gt;synchronous &lt;strong&gt;Ja&lt;/strong&gt;vaScript and &lt;strong&gt;X&lt;/strong&gt;ML.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  Definition of Ajax
&lt;/h4&gt;

&lt;p&gt;"Asynchronous JavaScript + XML, while not a technology in itself, is a term coined in 2005 by &lt;strong&gt;Jesse James Garrett&lt;/strong&gt;, that describes a "new" approach to using a number of existing technologies together.&lt;br&gt;
&lt;strong&gt;...&lt;/strong&gt;&lt;br&gt;
When these technologies are combined in the Ajax model, web applications are able to make quick, incremental updates to the user interface without reloading the entire browser page. This makes the application faster and more responsive to user actions."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;MDN web docs, quoted 2019-01-20 from the&lt;/em&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX" rel="noopener noreferrer"&gt;source article&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How is Ajax &lt;em&gt;often&lt;/em&gt; used?
&lt;/h2&gt;

&lt;p&gt;Well, Ajax can be hidden in anything you see on the web, from asynchronously loading you Twitter feed when you scroll around on a Friday afternoon , to adding new products from an administration panel on a shopping site.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ajax is mostly used to fetch data during runtime from client side.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I start using Ajax?
&lt;/h2&gt;

&lt;p&gt;Assuming that you already have an &lt;a href="https://sv.wikipedia.org/wiki/HTML" rel="noopener noreferrer"&gt;HTML&lt;/a&gt;, &lt;a href="http://www.php.net/" rel="noopener noreferrer"&gt;PHP&lt;/a&gt; or similar file, and a working internet connection, you can either download JQuery directly from their website and linking to it as a file on your server, or get it using a &lt;a href="https://en.wikipedia.org/wiki/Content_delivery_network" rel="noopener noreferrer"&gt;CDN&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this article I will show you how to get it using JQuery's public CDN.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Get the latest version of JQuery
&lt;/h4&gt;

&lt;p&gt;Visit &lt;a href="https://code.jquery.com/" rel="noopener noreferrer"&gt;this page&lt;/a&gt; where you have a list of different versions of JQuery. I suggest you to pick a minified package. Copy the HTML code shown, it should look something like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;script
  &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://code.jquery.com/jquery-3.3.1.min.js"&lt;/span&gt;
  &lt;span class="na"&gt;integrity=&lt;/span&gt;&lt;span class="s"&gt;"sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="&lt;/span&gt;
  &lt;span class="na"&gt;crossorigin=&lt;/span&gt;&lt;span class="s"&gt;"anonymous"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  2. Open up your HTML/PHP/&lt;em&gt;etc&lt;/em&gt; file
&lt;/h4&gt;

&lt;p&gt;Paste the script tag at the top (in the head tag) or at the bottom (under the body tag) of your page. &lt;strong&gt;I suggest you put it at the bottom&lt;/strong&gt; in case something fails when loading the JQuery library, some of you may have other preferences.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My Site&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="c"&gt;&amp;lt;!-- Here --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        Hello World
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Or Here --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  3. Done!
&lt;/h3&gt;
&lt;h2&gt;
  
  
  HTTP methods
&lt;/h2&gt;

&lt;p&gt;When sending requests and data over the web, we can use one of the two main methods:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Post&lt;/li&gt;
&lt;li&gt;Get&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(Read more about &lt;a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods" rel="noopener noreferrer"&gt;HTTP Request methods here&lt;/a&gt; or &lt;a href="https://www.w3schools.com/tags/ref_httpmethods.asp" rel="noopener noreferrer"&gt;here (W3Schools)&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F82wt2jmxp0qxarpj5kp3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F82wt2jmxp0qxarpj5kp3.jpg" alt="Difference between post and get"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Post
&lt;/h2&gt;

&lt;p&gt;Post is used to send data "invisible", in most cases post is the way to go because you can send a ton more data with post than you can with get.&lt;/p&gt;
&lt;h3&gt;
  
  
  Security
&lt;/h3&gt;

&lt;p&gt;If the client that uses the page is connected to a secure WI-FI with &lt;a href="https://sv.wikipedia.org/wiki/WPA" rel="noopener noreferrer"&gt;WPA or WPA2&lt;/a&gt;, the post method is the most secure method. It may still better that get even if the user where using an unprotected network...&lt;/p&gt;
&lt;h3&gt;
  
  
  Applications
&lt;/h3&gt;

&lt;p&gt;Post is often used when transferring or receiving little to tons of data. It’s even used when communicating to web servers, databases or APIs as mentioned earlier.&lt;/p&gt;

&lt;p&gt;For example when you have a shopping basket with some products you want to buy, when you click “proceed” and are redirected do another page, your products follows you. &lt;em&gt;(This is also possible to be handled by the server using sessions, but that’s not to discuss in this particular article.)&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Get
&lt;/h2&gt;

&lt;p&gt;What most people think about when they hear “Get”, is URL queries. The get method is usually the way a user &lt;strong&gt;manually&lt;/strong&gt; communicate with a web page or API, specifying search terms, date ranges, or other information that defines the query.&lt;/p&gt;

&lt;p&gt;Wikipedia describes the HTTP get request method as only retrieving information from the server. Where some data can be configured via the web pages URL, or “query string”. &lt;em&gt;(See picture below)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkkjornjatqcecsc8gz2e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkkjornjatqcecsc8gz2e.jpg" alt="URL Query example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get is more &lt;em&gt;open&lt;/em&gt; to the user. This have both pros and cons.&lt;/p&gt;
&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;p&gt;If made the right way, get can be a way to talk to the web page and customize his/hers experience. For example; you visit a site with some controls, changing these controls and applying changes causes the page to reload, but also with some additional code in the URL. This is called an URL query. Here you see the values of those controls that you changed, and are now able to change them directly from the URL. Just type a new value and hit enter. This is often used by API services.&lt;/p&gt;
&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;p&gt;Giving control to the user is always dangerous. One worst scenario is having a reflective form using get to submit comments to an insecure website. If the website is vulnerable to cross site scripting (XSS) and just printing everything users type, into the source page... Get may be exploited as an walk around to ex; chromes XSS detection, built in protection systems, etc.&lt;/p&gt;

&lt;p&gt;There are of course many more pros and cons to take into account. But this is just to give you a quick glimpse.&lt;/p&gt;
&lt;h2&gt;
  
  
  Comparison
&lt;/h2&gt;

&lt;p&gt;Get &lt;em&gt;only&lt;/em&gt; allows you to send key-value pairs, unlike post that can send whole object, files, tables and much more. Read more about &lt;a href="https://en.m.wikipedia.org/wiki/POST_(HTTP)" rel="noopener noreferrer"&gt;the capacity of get &amp;amp; post&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Important!
&lt;/h2&gt;

&lt;p&gt;Remember when we pasted the script tag that enabled us to use JQuery? Well, code is always executing in cascading order and code that rely on other code must be executed after the code that it’s relying on. What I’m trying to say is always put your own script tags of depending JavaScript underneath the JQuery tag. This may otherwise stop execution of your website and not run JavaScript as expected.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h1&gt;
  
  
  Usage
&lt;/h1&gt;

&lt;p&gt;Okay... Let's finally get down to business.&lt;/p&gt;

&lt;p&gt;The Ajax methods are accessed by typing &lt;code&gt;$&lt;/code&gt;. This is the &lt;a href="https://learn.jquery.com/using-jquery-core/jquery-object/" rel="noopener noreferrer"&gt;jQuery Object&lt;/a&gt;. Following up with a &lt;code&gt;.&lt;/code&gt; and you'll see a list of all functions JQuery has to offer.&lt;/p&gt;
&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;
&lt;h3&gt;
  
  
  $.ajax
&lt;/h3&gt;

&lt;p&gt;jQuery’s core &lt;code&gt;$.ajax()&lt;/code&gt; method is a powerful way of creating Ajax requests. It requires an object that contains all the configurations Ajax needs to send the request.&lt;/p&gt;
&lt;h4&gt;
  
  
  Parameters
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;type/method&lt;/td&gt;
&lt;td&gt;Which type of HTTP method is going to be used?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;url&lt;/td&gt;
&lt;td&gt;Where are we going to send this request to?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;What data are we going to send the destination?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Events
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;success&lt;/td&gt;
&lt;td&gt;A function that's called when Ajax returns any data.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An Example of this may look like the following:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;www.example.com/subfolder/page.php&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;myLuckyNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

Lucky number was registered!


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  $.post
&lt;/h3&gt;

&lt;p&gt;Load or send data from the server using a HTTP POST request. It requires an object that contains all the configurations Ajax needs to send the request.&lt;/p&gt;
&lt;h4&gt;
  
  
  Parameters
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;url&lt;/td&gt;
&lt;td&gt;Where are we going to send this request to?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;What data are we going to send the destination?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Events
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;success&lt;/td&gt;
&lt;td&gt;A function that's called when Ajax returns any data.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An Example of this may look like the following:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;www.api.mydomain.com/register.php&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                &lt;span class="c1"&gt;// User 1, aka data.users[0]&lt;/span&gt;
                &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;//data.users[0].name&lt;/span&gt;
                &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;54&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;        &lt;span class="c1"&gt;//data.users[0].age&lt;/span&gt;
                &lt;span class="na"&gt;work&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hacker&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;//data.users[0].work&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Billy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;work&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;road worker&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nathan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;work&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unemployed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

3 new user(s) where registered!


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  $.get
&lt;/h3&gt;

&lt;p&gt;Load or send data from the server using a HTTP GET request. It requires an object that contains all the configurations Ajax needs to send the request.&lt;/p&gt;
&lt;h4&gt;
  
  
  Parameters
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;url&lt;/td&gt;
&lt;td&gt;Where are we going to send this request to?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;data&lt;/td&gt;
&lt;td&gt;What data are we going to send the destination?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Events
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;success&lt;/td&gt;
&lt;td&gt;A function that's called when Ajax returns any data.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An Example of this may look like the following:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://www.google.se&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;itemscope=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;itemtype=&lt;/span&gt;&lt;span class="s"&gt;"http://schema.org/WebPage"&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"sv"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"origin"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"referrer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"/images/branding/googleg/1x/googleg_standard_color_128dp.png"&lt;/span&gt; &lt;span class="na"&gt;itemprop=&lt;/span&gt;&lt;span class="s"&gt;"image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"origin"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"referrer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Google&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
...


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Execute JavaScript Files with Ajax!
&lt;/h2&gt;

&lt;p&gt;Load and execute a JavaScript file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dataType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;script&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Parse with Ajax!
&lt;/h2&gt;

&lt;p&gt;Because Ajax sends HTTP request to a web server, it also receives HTTP/HTML/JSON formatted responses. With this in mind, we can pretend that our Ajax is our browser, and send requests to a web server that we want a normal html page for example. &lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" rel="noopener noreferrer"&gt;CORS&lt;/a&gt; &amp;amp; &lt;a href="https://www.chromestatus.com/feature/5629709824032768" rel="noopener noreferrer"&gt;CORB&lt;/a&gt; policies
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cross-Origin Resource Sharing&lt;/strong&gt; &lt;em&gt;(CORS)&lt;/em&gt; is additional HTTP headers that tells the browser to let a web application running at one &lt;em&gt;origin&lt;/em&gt;, or domain have permission to access selected resources from a server at a different &lt;em&gt;origin&lt;/em&gt;, or domain.This means that web pages that doesn't have the same &lt;em&gt;origin&lt;/em&gt;, or domain &lt;strong&gt;can share resources&lt;/strong&gt; &lt;em&gt;(See image below)&lt;/em&gt;.&lt;br&gt;
As long as the server is configured to allow requests from your or any other web application's origin, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest" rel="noopener noreferrer"&gt;XMLHttpRequest&lt;/a&gt; and &lt;strong&gt;Ajax&lt;/strong&gt; will work.&lt;/p&gt;

&lt;p&gt;Sadly, some websites are protected by something called &lt;strong&gt;Cross-Origin Read Blocking&lt;/strong&gt; &lt;em&gt;(CORB)&lt;/em&gt;. this is an algorithm that can identify and block "cross-origin" resource loads in web browsers before they reach the web page. This means that web pages that doesn't have the same &lt;em&gt;origin&lt;/em&gt;, or domain &lt;strong&gt;can not share resources&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmdn.mozillademos.org%2Ffiles%2F14295%2FCORS_principle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmdn.mozillademos.org%2Ffiles%2F14295%2FCORS_principle.png" alt="CORS principle"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you look at the code below, a new Ajax request is created to a site that is using CORS. This means that we can request the HTML code via an Get method.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;// This is just an example domain&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;sucess&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sourceCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sourceCode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;itemscope=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;itemtype=&lt;/span&gt;&lt;span class="s"&gt;"http://schema.org/WebPage"&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"sv"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"origin"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"referrer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"/images/branding/googleg/1x/googleg_standard_color_128dp.png"&lt;/span&gt; &lt;span class="na"&gt;itemprop=&lt;/span&gt;&lt;span class="s"&gt;"image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"origin"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"referrer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Google&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
...



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Ajax progress!
&lt;/h2&gt;

&lt;p&gt;In JQuery there's no straight way to fetch the progress that an &lt;code&gt;$.ajax()&lt;/code&gt; request have made, but the method supports an custom &lt;strong&gt;xhr&lt;/strong&gt; object.&lt;/p&gt;

&lt;p&gt;What we did in the example below, was creating out own xhr object that preforms the HTTP request, and added an event listener for "progress" to it. This made it possible for us to grab the current state in percent of the request.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  xhr
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;$.ajax()&lt;/code&gt; function returns the XMLHttpRequest object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the xhr option.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;JQuery AJAX documentation, quoted 2019-01-20 from the&lt;/em&gt; &lt;a href="https://api.jquery.com/jQuery.ajax/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://example.url/very/large/image.jpeg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="na"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;xhr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;progress&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;evt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;evt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lengthComputable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;percentComplete&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;evt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loaded&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;evt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;percentComplete&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

0.2384341119115186
0.7248216529871057
1


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It is also possible to fetch the progress on contacting the server instead of capturing the response by replacing &lt;code&gt;xhr.addEventListener(...)&lt;/code&gt; to &lt;code&gt;xhr.upload.addEventListener(...)&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Closure
&lt;/h2&gt;

&lt;p&gt;Thanks for reading this article! I hope it helped you on your journey to become a JavaScript and JQuery master! Share this with your friends and family that might be interested or benefit of this information.&lt;/p&gt;

&lt;p&gt;If you have any questions what so ever, I'd be glad to answer them in the discussion down below.&lt;/p&gt;




&lt;h3&gt;
  
  
  Credits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://cdn.artandlogic.com/wp-content/uploads/2000px-AJAX_logo_by_gengns.svg_.png" rel="noopener noreferrer"&gt;Cover Image&lt;/a&gt; by Christopher Keefer&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://thepracticaldev.s3.amazonaws.com/i/ytxdmm71yvt3zokkrpn4.jpg" rel="noopener noreferrer"&gt;Difference between post and get&lt;/a&gt; by Me&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www-growyourgk-com.cdn.ampproject.org/i/s/www.growyourgk.com/wp-content/uploads/2017/08/querystring-in-javascript.jpg" rel="noopener noreferrer"&gt;Url Query Example&lt;/a&gt; by Hari Prasad&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://mdn.mozillademos.org/files/14295/CORS_principle.png" rel="noopener noreferrer"&gt;CORS principle&lt;/a&gt; by MDN web docs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  People who helped make this article better
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dev.to/emgodev"&gt;Michael Goldspinner&lt;/a&gt; with feedback&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ajax</category>
      <category>javascript</category>
      <category>jquery</category>
      <category>php</category>
    </item>
  </channel>
</rss>
