I’ve some strings in the backend function,
how do i pass that string to front end page.
Hey
If you do not add or share code it will be harder for anyone to help you. Usually you must return the string or object from the backend to the frontend.
So let’s say you have a backend function called searchDatabase that you call in your page code.
This is one way to wait for a promise from the backend function. This way you don’t use await / async.
searchDatabase().then((results) => {
console.log(results);
})
The other way would be to use await / async methods.
let results = await searchDatabase();
That code must be inside a function that has the async keyword added before function.
In your backend function just make sure you return something back to the calling function.
sorry for the delayed reply, i found out the problem, the function is not executing line by line even if the async key word is not defined. can you kindly help me in this. (I want it to execute line by line)
This is my front end code
export function button1_click(event) {
//Add your code for this event here:
let apno = “10011”;
let name = $w(‘#input1’).value;
let mob = “8489878428”;
let amount = $w(‘#input6’).value;
let conferenct = “RTSYM19”;
let conferenceyear = “2019”;
let paymode = “CITRUS”;
let address = “”;
let adress1 = “”;
let city = “”;
let state = “”;
let pincode = “”;
let phone = “”;
let mobile = “”;
let email = “”;
let foodtype = “”;
let participanttype = “”;
let practicetype = “”;
let members = “”;
let remoteip = “”;
let ur1 = “”;
let trid = “”;
var res = “”;
var err11 = “”;
let uuu = “”;
let Transid = “”;
let ResultCode = “”;
var url = ‘https://clin.cmcvellore.ac.in/testconference/ConferencePay.asmx?wsdl’;
var args = {
regno: apno,
cname: name,
mobile: mob,
totalregfee: amount,
conference: conferenct,
confyear: conferenceyear,
bankname: paymode,
address: address,
address1: adress1,
city: city,
state: state,
pincode: pincode,
phone: phone,
email: email,
foodtype: foodtype,
participanttype: participanttype,
practicetype: practicetype,
members: members,
remoteip: remoteip
};
wixData.save("participants", args, options);
//console.log(“hi”);
//let res2123 = await gateCall(args);
//let r1 = String(res2123);
//console.log(r1);
gateCall(args).then(product => {
let r12 = product;
console.log(r12);
//wixLocation.to(r12);
})
. catch (error => {
console.log(error);
});
//console.log(“hi2”);
let options = {
“suppressAuth”: true ,
“suppressHooks”: true
};
let u1 = uuu;
console.log(uuu);
gatetry();
}
function gatetry() {
wixData.query("myCollection").find().then((results) => {
let num = results.length; //see item below
let n3 = results.totalCount;
let n4 = results.next();
let resF = results.items[0];
console.log(num);
console.log(resF);
console.log(n4);
let t1 = resF.finalURL;
console.log(“external” + t1);
wixLocation.to(t1);
})
. catch ((err) => {
let errorMsg = err;
console.log(errorMsg);
});
//wixData.query(“collectionName”).
}
Backend code
import wixData from ‘wix-data’;
import request from ‘request’;
//import wixLocation from ‘wix-location’;
//import asdf from ‘asdf’;
export function gateCall(args) {
let ur1 = “”;
let trid = “”;
var res = “”;
var err11 = “”;
let URL = “”;
let Transid = “”;
let ResultCode = “”;
var out1 = “”;
//str1 = “i am a string”;
//var soap = require(‘soap’);
var url = ‘https://clin.cmcvellore.ac.in/testconference/ConferencePay.asmx?wsdl’;
var passARG = “”;
let finalURL = “”;
var output = “”;
console.log(“hi3”);
request.post({ url: 'https://clin.cmcvellore.ac.in/testconference/ConferencePay.asmx/CONFONLINEPAYSAVE', form: args }, function (err, httpResponse, body) { /* ... */
console.log('error:', err); // Print the error if one occurred
console.log('statusCode:', httpResponse && httpResponse.statusCode); // Print the response status code if a response was received
output = body;
out1 = output;
var out11 = out1;
var rc1 = out11.split(“”, 2);
var rc2 = rc1[1].split(“”, 1);
var finalRC = rc2[0];
if (finalRC === “0”) {
var ur11 = out11.split(“”, 2);
var ur12 = ur11[1].split(“”, 2);
var ur13 = ur12[0].replace(“amp;”, “”);
finalURL = ur13;
var tr1 = out11.split(“”, 2);
var tr2 = tr1[1].split(“”, 1);
var finalTRID = tr2[0];
var re1 = out11.split(“”, 2);
var re2 = re1[1].split(“”, 1);
var finalREG = re2[0];
//console.log(finalRC);
//console.log(finalREG);
//console.log(finalTRID);
//console.log(finalURL);
let options = {
“suppressAuth”: false ,
“suppressHooks”: false
};
passARG = { finalRC, finalTRID, finalREG, finalURL };
//console.log(passARG);
wixData.save(“myCollection”, passARG, options).then((results) => {
let item = results; //see item below
console.log("in1 " + results.finalURL);
// wixLocation.to(results.finalURL);
})
. catch ((err12) => {
let errorMsg = err12;
});
return finalURL;
}
return finalURL;
});
return finalURL;
}
i want the backend to return finalURL for the page to navigate to it.
Thanks in advance
Hey
In the backend function you will need to do the return in the Promise you get when saved the item to the data collection. Otherwise you won’t wait for it and you will return nothing.
return wixData.save("myCollection", passARG, options).then((results) =>
{
let item = results; //see item below
console.log("in1 " + results.finalURL);
return finalURL;
// wixLocation.to(results.finalURL); })
.catch((err12) => {
let errorMsg = err12;
});
I am also unsure of the request post you use instead of fetch but if you have that working and it works then leave it as it is.
Thank you for the information… will try it out…