0

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!

2

1 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.