_tony
1
Hi,
I am new to Wix Code, having started using it just earlier today.
I am now using the code below to populate a collection from a field (write-only). I wonder how I could modify it to collect the User’s IP address?
Most grateful,
Tony
import wixData from ‘wix-data’;
export function button1_click(event) {
const inID= $w(‘#Input’).value;
let toInsert = {
“title”: inID,
};
wixData.insert(‘my-collection’, toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
}
_tony
2
anyone?
My first attempt at writing a code but it is not working yet:
import wixData from ‘wix-data’;
//export function myRouter_Router(request) {
export function button1_click(event) {
const ip = request.ip;
let toInsert = {
“ip”: ip,
};
wixData.insert(‘my-collection’, toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
}
Hi Tony,
You can fetch the ip address using external API’s such as https://www.ipify.org/ and https://whatismyipaddress.com/api
Please note that the ip address may change and you should not count on it to be constant.
Cheers,
Mor