jQuery: wait for function to complete to continue processing?

后端 未结 9 1131
轮回少年
轮回少年 2020-12-06 00:28

Hey all. I have, what appears to be, a trivial problem. I have the following JavaScript:

$(function() {
    var r = GetResults();

    for(var i = 0; i <         


        
9条回答
  •  感动是毒
    2020-12-06 01:14

    I've run into something similar before. You'll have to run the ajax call synchronously.

    Here is my working example:

    $.ajax({
        type: "POST",
        url: "/services/GetResources",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: '{resourceFileName:"mapedit",culture:"' + $("#lang-name").val() + '"}',
        cache: true,
        async: false, // to set local variable
        success: function(data) {
            localizations = data.d;
        }
    });
    

提交回复
热议问题