diff options
author | Paulo Moura <itsme@paulomoura.com> | 2017-10-06 11:37:59 +0300 |
---|---|---|
committer | Jos Poortvliet <jos@opensuse.org> | 2017-10-06 12:07:09 +0300 |
commit | 1c2025b32c5039fbb7e72f9202b4354751ebcbbf (patch) | |
tree | d7cb6eed477658bf7010d0f13b0cfd6c84cf8b11 /page-providers.php | |
parent | b4ddd862ae1461267cdff3765acacd1ea1cd05b9 (diff) |
use vanilla javascript to get the providers json
Diffstat (limited to 'page-providers.php')
-rw-r--r-- | page-providers.php | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/page-providers.php b/page-providers.php index b977210e..c912454b 100644 --- a/page-providers.php +++ b/page-providers.php @@ -128,17 +128,34 @@ html: filteredItems.join("") }).appendTo('#providers'); } - $.getJSON('<?php echo get_template_directory_uri() ?>/assets/providers.json', function (data) { - items = data; - shuffle(items); - filterItems(selectedCountryCode, filterFreePlans, filterHosting); - $.each(countries, function (key, countryCode) { - $('#countryPicker').append($('<option/>', { - value: countryCode, - html: countryCode - })); - }); - }); + + var request = new XMLHttpRequest(); + request.open('GET', '<?php echo get_template_directory_uri() ?>/assets/providers.json', true); + + request.onload = function() { + if (request.status >= 200 && request.status < 400) { + items = JSON.parse(request.responseText); + + shuffle(items); + filterItems(selectedCountryCode, filterFreePlans, filterHosting); + + $.each(countries, function (key, countryCode) { + $('#countryPicker').append($('<option/>', { + value: countryCode, + html: countryCode + })); + }); + } else { + // We reached our target server, but it returned an error + + } + }; + + request.onerror = function() { + // There was a connection error of some sort + }; + request.send(); + $('#countryPicker').change(function () { selectedCountryCode = $(this).find("option:selected").attr('value'); filterItems(selectedCountryCode, filterFreePlans, filterHosting); |