Reputation: 43
I have a variable as per below:
var myip;
And I want to insert it in the url below:
$.ajax('http://api.ipstack.com/**[myip]**?access_key=mykey')
If I manually put in my ip in place of [myip] it gives me the desired results but I want to automate it.
I tried with the methods given in the url below but it didn't help.
How to pass Javascript variables inside a URL? AJAX
Thanks in advance for going through and helping!
Upvotes: 0
Views: 67
Reputation: 37755
Use string template.
$.ajax(`http://api.ipstack.com/${myip}?access_key=mykey`)
^ ^^^^^^^ ^
Or using string concatenation.
$.ajax('http://api.ipstack.com/' + myip + '?access_key=mykey')
Upvotes: 1