I need help, please. How can I associate the IP address in this context to dmx.value or at least use the result in an HTML input field. I don’t speak a single word in javascript.
< script type=“application/javascript” >
function getIP(json) {
document.write("My public IP address is: ", json.ip);
}
</ script>
Hi @george. I actually have the API function running to pick IP address. However, it passes me my own server IP address. This solution is to retrieve client IP address, pass it to an API function that will retrieve everything else I need from the client IP address.
So I get this: apiurl.php?mykey&ipaddress
This function does retrieve client IP address, I just don’t know how to put it in a form input field to pass it to the API.
How critical is this function? Fetching the IP address client-side is not a very wise idea from a security standpoint, as the user could manipulate the client-side code to return a different address. The problem here is you’re getting the server’s IP address instead of the client’s. A properly configured web server would be smart to pass the client’s IP address to your app
How are you hosting your website? Is it PHP or NodeJS? Are you using a load balancer in front? CloudFlare?
Hi @Apple. Actually, in my application, even a VPN connection is not a problem, but abstractapi.com also determines VPN connections. I just want a simplified form that captures vital geo and IP variables which the user can change later. Clunky it might seem, but if it is programmatically achievable, I’m going for it.
However, that function shoots the client IP, how to get it off javascript into an HTML input field is what beats the S*** out of me. I know it’s simple, I just don’t know-how. **sigh
You can use dmx.parse within a script to set the value of a dmx variable.
For example
< script type=“application/javascript” >
function getIP(json) {
document.write("My public IP address is: ", json.ip);
dmx.parse.var1.setValue(json.ip);
}
</ script>
You could also set the value of an input directly.
If json.ip is the value from the script, and var1 is a variable on a content page, then the above looks correct to me. Use the dev console to troubleshoot. Put a console.log(json.ip) in there to make sure it is evaluating, etc.
ypeError: Cannot read properties of undefined (reading 'get')
at t (parser.js:695:1)
at parser.js:780:1
at parser.js:740:1
at parser.js:495:1
at Object.dmx.parse (parser.js:428:1)
at getIP (register.html:106:41)
at ?format=jsonp&callback=getIP:1:1
dmx.parse @ parser.js:430
getIP @ register.html:106
(anonymous) @ ?format=jsonp&callback=getIP:1
**register.html:107 94.205.33.7**
routes.js:1 Uncaught TypeError: Cannot set properties of undefined (setting 'router')
at routes.js:1:20
< script type=“application/javascript” >
function getIP(json) {
document.write("My public IP address is: ", json.ip);
dmx.global.set('ipadd',json.ip);
}
</ script>
You can then use it in data bindings such as:
<input type="text" dmx-bind:value="ipadd">
When are you calling the getIP function? When the API request completes? Do you see the ‘My public ip is’ text on your page?
IGNORE the question about when - I can see it’s a callback from the script