AJAX Request Using Vanilla JavaScript

👋 Ciprian on Friday, September 15, 2017 in Blog
Last modified on Friday, September 15, 2017

Learn JavaScript by example. Code snippets, how-to's and tutorials. Try now!

This is how you create an AJAX request with optional GET parameters in vanilla JavaScript. Note that you need to be on the same domain for the AJAX call to work.

JavaScript

function recordAb(parameters) {
    var xhttp = new XMLHttpRequest();

    xhttp.open('GET', 'https://www.example.com/receiver.php', true);
    xhttp.send();
}

Usage

recordAb('?this=1&that=2');

Find more JavaScript tutorials, code snippets and samples here.

Buy me a coffee to support my work!

👋 Added by Ciprian on Friday, September 15, 2017 in Blog. Last modified on Friday, September 15, 2017.

Leave a Reply

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Privacy Policy