webmodules / jsonp

A simple JSONP implementation
1.91k stars 332 forks source link

multiple jsonp requests on same page failing with timeout error #31

Open mandard24 opened 7 years ago

mandard24 commented 7 years ago

Hi,

I'm doing multiple jsonp calls from one page to get a set of images for each of the product that will be rendered on the page. Even though I see all the requests return response(status - 200) for each of the jsonp call, I'm only able to get the data for one product only(mostly its the last product on the page).

IMPORTANT: all the jsonp requests uses same callbackto return the content.

I'm using React component to render product list by iterating through an array. Every time a new product list component is called/created, i make the jsonp request to fetch the set of images and display on the page.

When my page renders I see only one of the product shows the list of images. And rest of the jsonp request end up in 'Timeout' error.

Can someone show me how to make these multiple jsonp requests each with the same jsonp callback that simply gets content for each of the product? console-error network-requests-success

alliuca commented 7 years ago

can you change the callback prefix on each request? that's how I solved my issue. Something like:

jsonp(${url}&callback=${cbPrefix}, { timeout: 1000, prefix: cbPrefix }, (err, data) => {

that cbPrefix is different at each request