Hi all,
II’m having an issue where everything in my page works fine in preview mode but as soon as I publish it, it doesn’t work.
A bit of background:
My code takes an input and basically matches that input with a URL from a certain carrier (url is determined by first 3 digits of the input), puts both the URL and input into a data set on change, and when the user presses the search button the page redirects to a “tracking redirect” page that concatenates the two inputs and goes to that URL.
Problem:
This all works in preview. I debug by console.log-ing the key variables which all show up fine in preview. When I publish it, the URL that’s supposed to be matched returns as “undefined” instead of what it should be.
Why would this happen? Shouldn’t preview mode be an accurate representation of the site’s behavior before actual launch?
My code is below:
import wixData from 'wix-data';
$w.onReady(function () {
$w('#AWB').show('fly')
$w('#searchawb1').show('fade')
});
export async function AWB_change(event) {
$w('#text35').hide('fade')
//user input
let AWB = $w('#AWB').value
//to determine airline
let prefix = AWB.slice(0,3)
//to append url with
let suffix = AWB.slice(3)
let info = await query_airline(prefix)
let carrier = info[0]
$w('#text36').text = "Searching " + carrier
let i = info[1]
let baseurl = await get_url(i)
// this is where the issue is: working in preview but not published
console.log(baseurl)
//saves reference and url to dataset that pulls in next redirect page
await save_dataset(suffix, baseurl)
}
function query_airline(prefix){
return wixData.query('Airlines')
.contains('awbPrefix', prefix)
.find()
.then( (results) => {
if(results.items.length > 0) {
let items = results.items;
let info = [items[0].airline, parseInt(items[0].index,10)]
return info
} else {
$w('#text35').show('fly')
}
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} )
}
function get_url(i){
let url_array = [
'https://www.ups.com/actrack/track/submit?awbNum=406',
'https://freight.qantas.com/online-tracking.html?airWaybills=081-',
'https://www.cathaypacificcargo.com/ManageYourShipment/TrackYourShipment/tabid/108/SingleAWBNo/160-',
'https://www.airnewzealand.co.uk/international-cargo-track-and-trace',
'https://www.brcargo.com/ec_web/Default.aspx?Parm2=191&Parm3=?TNT_FLAG=Y&AWB_CODE=695&MAWB_NUMBER='
]
return url_array[i]
}
async function save_dataset(suffix, baseurl){
$w("#dataset1").setFieldValue("reference", suffix)
$w("#dataset1").setFieldValue("url", baseurl);
$w("#dataset1").save();
}
ANY suggestions would help.
Thank you!!!