Multiple GetJSON without response

Hello everyone,

I’m trying to sync between a software and the wix database but I have a problem when I try to make several requests.

Here is my code: CodePile | Easily Share Piles of Code

Here the input in console.log :

page : 0 loading
page : 0 loaded
page : 1 loading

Why page 1 is not loaded ?

The url is correct, no error detected.

An idea of the problem ?

Thanks,

Yannik

Easier if you post your code in the same post too and not expect forum users to go elsewhere to see it.

For starters you are missing the onReady page function.
https://www.wix.com/corvid/reference/$w.html#onReady

Also, have a read of the Wix Fetch API getJSON function as you might need to put it into a backend file like you normally would when you use Wix Fetch.
https://www.wix.com/corvid/reference/wix-fetch.html#getJSON
https://www.wix.com/corvid/reference/wix-fetch.html

Also, make sure that if your site is https, that you are also requesting HTTPS content, if you are requesting HTTP content then it won’t work.

import wixData from 'wix-data';
import { getJSON } from 'wix-fetch';

const rowPerPage = 10;

export function get() {

loadProperties(0).then((result) => {

loadProperties(result + 1).then((result) => {

}).catch((error) => {
console.log(error.message);
console.log(error.code)
});

}).catch((error) => {
console.log(error.message);
console.log(error.code)
});

}

function loadProperties(page) {

console.log('page : ' + page + ' loading');

return getJSON('http://example.com?request="ClientId":"XXXXXXX","Page":'+page+',"RowsPerPage":'+rowPerPage+'}')
.then(json => {

console.log('page : ' + page + ' loaded');

return page;
}).catch((error) => {
console.log(error.message);
console.log(error.code)
});
}

Hi,

Thanks for the interest in my problem.

I do not have any problems with the execution of the script.

I actually use onReady to test it on my Homepage.

It works for the first call to the function loadProperties (see the information of the console that I posted above) but during the 2nd call ( see loadProperties(result + 1) ), I have no console log generated.

I posted the code on another site because I had problems with indentation. I found it clearer than in the post.