0

I am calling an external API where it will create a file(zip file) based on the requirements, but to create a file it will take 3-5 minutes. my code was before

 $.ajax({
        url: 'myPage.php',
        data: entries,
        success: function(data) {
            console.log(data);
        }
    });

It will create a file in the backend but it does not send a response. After sometime I see the 504 error in the console. In the external API, only after the file is created it will return a JSON response.

So, I implemented the jquery promise

function functABC(entries, requrl) {
  return new Promise(function(resolve, reject) {
    $.ajax({
      url: requrl,
      data: entries,
      success: function(data) {
        resolve(data) // Resolve promise and go to then()
      },
      error: function(err) {
        reject(err) // Reject the promise and go to catch()
      }
    });
  });
}

functABC(entries, requrl).then(function(data) {
  console.log(data)
}).catch(function(err) {
  console.log(err)
})

The above code returns Null and in the external API I see the following error

400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Is the above jquery promise code correct or should i need to add something?

An answer would be helpful

0 Answers0