Use ajax many requests, and the result set (ajax non-asynchronous)

Directly on the bar code ... there are comments

<! DOCTYPE HTML> 
<HTML> 
    <head> 
        <Meta charset = "UTF-. 8" /> 
        <title> </ title> 
        <Script the src = "JS / jQuery-3.4.1.js"> </ Script> 
    < / head> 
    <body> 
        <Script> 
            
            ( function () {
                 var data = {stuId: '4231' };
                 var List = []; 
                getInfo ( function (data, obj) {
                     // first query no data or bar 3 does not satisfy the number of data segmentation parameter 
                    IF (data) { 
                        list.push (data);
                    }else{
                        // Parameter division 
                        var stuIds obj.stuId.split = ( "" );
                         // cycle requests to obtain data 
                        for ( var I = 0; I <stuIds.length; I ++ ) {
                             // parameter object 
                            var obj = {stuId: stuIds [I]};
                             // first determine whether the list of the number of whether the condition 
                            iF (List.length> = 2 ) {
                                 // suspend request 
                                BREAK ;
                                 // the throw Error ( "condition is satisfied, no request ..." ); 
                            } the else { 
                                getInfo (function (Data) {
                                     IF (Data) { 
                                        list.push (Data); 
                                    } 
                                }, obj); 
                            } 
                        } 
                    } 
                }, Data); 
                
                the console.log (List); 
            }) (); 
            
            // callback 
            function getInfo ( the callback, stuId) { 
                $ .ajax ({ 
                    the async: to false , // synchronization request 
                    type: 'GET', // request method
                    URL: 'http://127.0.0.1:8080/stu/findById', // request server address 
                    contentType: "file application / JSON", // encoding type setting contents to be transmitted 
                    Data: stuId, // parameter object 
                    success: function (Data) { // event upon completion of 
                        the callback (Data, stuId); 
                    }, 
                    error: function (error) { // event the error 
                        alert ( "abnormal." ); 
                    } 
                }); 
            }
         </ Script> 
    </ body> 
</ HTML>

 

Guess you like

Origin www.cnblogs.com/oukele/p/11576439.html