Execute function after Ajax call is complete

后端 未结 6 2026
遇见更好的自我
遇见更好的自我 2020-11-30 03:16

I am new to Ajax and I am attempting to use Ajax while using a for loop. After the Ajax call I am running a function that uses the variables created in the Ajax call. The fu

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 03:35

    You should set async = false in head. Use post/get instead of ajax.

    jQuery.ajaxSetup({ async: false });

        $.post({
            url: 'api.php',
            data: 'id1=' + q + '',
            dataType: 'json',
            success: function (data) {
    
                id = data[0];
                vname = data[1];
    
            }
        });
    

提交回复
热议问题