The data problem of using ajax to request data in vue

problem description

data problems of using ajax to request data in vue

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with a picture)
/ / send a request to a third party after success

                        for(var i in listIn){
                            var arr = listIn[i].key;
                            console.log(arr)
                            $.ajax({
                                type:"post",
                                url: listIn[i].url,
                                async: false,
                                data:{ arr : res.data.content.token},
                                dataType:"jsonp",
                                success:function(result){
                                    console.log(result);
                                    keep();
                                },
                                error: function(err){
                                    console.log(err)
                                    keep();
                                }
                            });
                        }
                        
                        

       var listIn = [
            {
                url: shimingPersonIn,
                key: "cookieValue"
            },
            {
                url: shimingUnitIn,
                key: "cookieValue"
            },
            {
                url: coprApplyLogin,
                key: "copyRighCookie"
            }
        ]

what result do you expect? What is the error message actually seen?

the arr in this data cannot get the value assigned above, so try to solve

.
Jun.21,2021

because the arr in data is not treated as a variable but as a string.
is changed to this

.
                    for(var i in listIn){
                            var arr = listIn[i].key;
                            let obj = {};
                            obj[arr] = res.data.content.token;
                            $.ajax({
                                type:'post',
                                url: listIn[i].url,
                                async: false,
                                data: obj,
                                dataType:'jsonp',
                                success:function(result){
                                    console.log(result);
                                    keep();
                                },
                                error: function(err){
                                    console.log(err)
                                    keep();
                                }
                            });
                        }
The

array structure is posted


  data:{ [arr] : res.data.content.token},

for loop using asynchronous operations. There should be a problem!
if you use vue, try axios to make the request.

Menu