The key is that setinterval cannot pass parameters, so it's good to wrap it up with an anonymous function.
//Reset Publish Progress Function resetpercent (id_data) {$.ajax ({url: '/autodeploy/reset_percent/' + id_data, Success:function (JSON) {},}); }; Interval refresh, display percent, Ajax call Rest_framework framework var _interval = {}; function Showpercent (id_data) {//var _interval; var Percent_value; var id_subserver = Id_data.split ("-") [0] $.getjson ("/api/subserver/" + id_subserver, function (data,state {if (state = = ' success ') {Percent_value_array = Data.deploy_status.split (","); Percent_value = percent_value_array[0]; Cmd_value = percent_value_array[1]; $ (' # ' + id_data). HTML ("<Divclass= ' Uk-progressuk-progress-striped uk-progress-active '><Divclass= ' Uk-progress-bar 'style= ' width:"+ percent_value +"%; '>"+ Cmd_value +" + percent_value + "%</Div><Iclass= ' Uk-icon-cogUk-icon-spin '></I></Div>"); Console.log (Percent_value[0]) if (percent_value! =) {//_interval = SetInterval (Showpercent (id_data), 3000); } else {clearinterval (_interval[id_data]); $ (' # ' + id_data). HTML ("<Divclass= ' Uk-progressuk-progress-striped uk-progress-success '><Divclass= ' Uk-progress-bar 'style= ' width:"+ percent_value +"%; '>100%</Div></Div>"); }; }; } ); }; $ (". Btn-multi-deploy"). Click (function () {var deploypool_id = $ (this). attr ("deploypool_id") var Group_da TA = $ ("#deploy-form" + deploypool_id). Serialize () var Deploy_type = $ (this). attr ("Deploy_type") var _se LF = this; Console.log (deploypool_id, Group_data)//Because of the AJAX output ID positioning in modal dialogs, two arrays are used to reset update progress and refresh percentages. can be optimized. var id_array = [] var id_s_array = [] var Group_array = Group_data.split ("&"); for (Var key_data in Group_array) {if (Group_array[key_data].indexof ("select-deployversion")! =-1) { deploy_id = Group_array[key_data].split ("=") [1]}; if (Group_array[key_data].indexof ("Check-server")! =-1) {Id_s_array.push (group_array[key_data].split ("=") [1]) Id_array.push (group_array[key_data].split ("=") [1] + "-" +deploy_id)}; }; Promisedeploy = $.ajax ({url: ' {% url ' autodeploy:group-cmd '%} ', type: ' Post ', data:{ Group_data:group_data, Deploy_type:deploy_type,}, DataType: ' JSON ', Beforesend:function () {result_output = $ (_self). Siblings ("P.result_output"); Result_output_desc = $ (_self). Siblings ("P.result_output_desc"); $ (_self). attr (' disabled ', "true"); $ (_self). Append ("<Iclass= ' Uk-icon-cogUk-icon-spin '></I>"); Result_output_desc.append ("<Strong>In the cluster release, please wait patiently ....</Strong>"); Result_output.html ("<Div>In the cluster release, please wait patiently ....</Div>"); Reset for before sending (Index=0;index<Id_s_array. length;index++) {resetpercent (Id_s_array[index]); }}, Success:function (JSON) {$ (_self). Children (' I '). Remove (); $ (_self). Append ("<i class= ' Uk-icon-check '></I>") result_output_desc.append ("<spanclass= ' uk-text-success '><Iclass= ' Uk-icon-check '></I></span>"); Result_output_desc.append ("<spanclass= ' uk-text-success '>Asynchronous queue distribution is complete and each server starts to update.</span>"); Get progress after sending for (Index=0;index<Id_array. length;index++) {var key= Id_array[index]; //_interval= setinterval (function () {showpercent (key)},3000); _interval[key]= setinterval (function () {showpercent (key);},3000); }}, Error:function () {Result_output_desc.append ("<span class= ' uk-text-muted '><BR>Server Internal Error</span>"); Result_output_desc.append ("<spanclass= ' Uk-text-danger '><Iclass= ' Uk-icon-remove '></I></span>"); $ (_self). Children (' I '). Remove (); Result_output.html ("<Div></Div>"); }, Complete:function () {}});/* End Cmd-run Stop */});
The last time the Ajax timed refresh multiple ID is incorrect, this time to ask the master after the completion