I'm trying to write some javascript to pick up a currency query in the URL and then use the existing Ajax post method from the website to load up the correct currency depending on what URL was linked to.
my-url.com/?currency=USD <- loads the site in US Dollars
my-url.com/?currency=GBP <- loads the site in British Pounds
my-url.com/?currency=EUR <- loads the site in EUROS
This is the stock code for the currency selector to change the currency on the website:
$('#currency').on 'change', ->
$.ajax(
type: 'POST'
url: $(this).data('href')
data:
currency: $(this).val()
).done ->
window.location.reload()
This is what I have done so far:
if (window.location.href.indexOf("?currency=EUR") >= 0) {
$.ajax(
type: 'POST'
url: $(this).data('href')
data:
currency: $(this).val()
).done
}
It does not work as I am not pulling in the currency into the post method, and probably other reasons too.
This is beyond my scope, would anyone know how I would go about setting the JS to check on load for a currency in the url, set that to the currency value in the script and POST?