i’m using fetch to send request but i get back data in XML
its seems that i cant get XML data back
someone know how?
Thanks
i’m using fetch to send request but i get back data in XML
its seems that i cant get XML data back
someone know how?
Thanks
Have you setup your Wix Fetch code correctly as it should be JSON.
https://www.wix.com/corvid/reference/wix-fetch.html
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api#backend-service-call
https://support.wix.com/en/article/corvid-calling-server-side-code-from-the-front-end-with-web-modules
@naimibaby , did you obtain a solution for bringing external xml feed into Wix site?
Thanks.
yes,
i use fetch code and use response type text
and then i installed node-module named fast-xml-parser
and use the following code:
on backend:
import parser from 'fast-xml-parser';
var xml
export function getShopsList() {
let url = "YOUR URL HERE"
fetch(url, {
method: 'get',
headers: {'Content-Type': 'application/XML'}
})
.then((httpResponse) => {
httpResponse.text()
.then((response) => {
xml = String(response);
xml=parser.parse(xml);
console.log("xml: ", xml);
})
return xml // (not really returned the json)
});
}
export function getShopsList2(){
return xml
}
i think there is a bug to get the return data after fetch to front end page
so i created new function named getShopsList2
It’s not a bug, it’s that you haven’t waited for the promise to resolve before returning the value so it returns the original undefined variable. Try this:
export function getShopsList() {
let url = "YOUR URL HERE";
return fetch(url, {
method: 'get',
headers: {'Content-Type': 'application/XML'}
})
.then((httpResponse) => {
return httpResponse.text()
.then((response) => {
xml = String(response);
xml=parser.parse(xml);
console.log("xml: ", xml);
return xml;
})
});
}
@skmedia Thanks works better now!