Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript – Can't append ip address to "GET" url

Everything gets appended to the url except for the ip address. The end of the url should look like this for example; ip=127.0.0.1. But the ip address is not being added. Any ideas?

Here is the code…

<!-- User-Agent IP Code -->
<script type="application/javascript">
function getIP(json) {
    $.get( "https://hook.us1.make.com/s86ki3rt515ieg1gr3f9xxc5ufdu59zb?" +location.search.substring(1), "user=" + navigator.userAgent, "ip=" + json.ip);
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
<!-- User-Agent IP Code -->

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I believe the issue is in the "$.get" line. I looks like your trying to concatenate the parameters in the string and they aren’t properly formatted. In the $.get() function it expects the params to be a single object. You can create an object with the params and put it in the function. I’m not sure how the navigator.userAgent or json.ip string is from the code you have provided but if you pass the params it should give you a good idea. Here is my code.

<!-- User-Agent IP Code -->
<script type="application/javascript">
function getIP(json) {
    let params = {
        user: navigator.userAgent,
        ip: json.ip
    };

    $.get("https://hook.us1.make.com/s86ki3rt515ieg1gr3f9xxc5ufdu59zb", params);
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
<!-- User-Agent IP Code -->
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading