AJAX Request Using Vanilla JavaScript

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.

Added by Ciprian on Friday, September 15, 2017 in Blog

Unlimited Automated Page Speed Monitoring & Tracking. Completely free.
Use SpeedFactor to track your website. It’s simple, reliable, and best of all, it’s free forever.
See how real people experience the speed of your website. Then find (and fix) your web performance problems.
Get Started

Related Articles


Privacy Policy