The back-to-back interaction between ajax and curl?

check
one of the features I need now is that ajax and curl interact with each other at least five times
for example, I
ajax-> call.php
will call me back
and then send it back to me
I"m going to call another call2.php
and give it to me again. I"m playing call3.php
php. All the interactions between curl and external server (API for other people)
how can this be achieved? how can this be achieved?.?

charge
this is the first API to call, and the data to be given
clipboard.png

I still have a good number to type.
how should I write this one?
my ajax is generated through click events

I think it is

success: function( data ){
            // 
          },

it"s just that if I play five times, I"ll have five times, which doesn"t seem to be appropriate.
is there any master who can teach me

Mar.20,2021

you can ajax the request once, but curl you can wait for the execution result of the first to execute the second until your termination condition is met, and then return the result to ajax

clipboard.png


first of all, if you need to call more than 3 api to complete this function, it is recommended that you reconsider the design of the function. From the perspective of development, this model has low efficiency and high maintenance rate.
second, if you do not need to handle the results of each successful call, it is recommended that you call calls.php, once and then execute curl calls to different api. three times in this file If you need to process the result of each successful call, you can consider Promise on the js side. For example:

 Promise.all([
            fetchContent(posts.curId),
            fetchContent(posts.next()),
            fetchContent(posts.next())
        ]).then((contents) => {
            // ;
            contents.forEach((content) => {
                console.log(content); 
            });
        }).then(() => {
            console.log(');
        }).catch((err) => { // 
            console.error(err);
        });
        
    function fetchContent(postId) {
        console.log('');
        return new Promise((resolve, reject) => {
            window.fetch(`http://mydomain.com/posts/${postId}`,{
                    method: 'GET'
            }).then((response) => {
                resolve(response.text());
            }, (err) => {
                reject(err);
            });
        });
    };

all you need is await and async.
you can write it like this:

  

are you sure you can cross-domain?

Menu