Ajax jquery async return value

前端 未结 3 1136
予麋鹿
予麋鹿 2020-11-30 14:10

how can i make this code to return the value without freezing the browser.
You can rewrite this with new method of course.

function get_         


        
3条回答
  •  生来不讨喜
    2020-11-30 14:38

    You can not make variable assignments this way (async). you must set the variables in the success handler.

    variableArray = new Array(); 
    
    get_char_val('x');
    get_char_val('y');
    
    function get_char_val(merk)
    {  
        var returnValue = null;
        $.ajax({   
            type:       "POST",
            url:            "char_info2.php",   
            data:   { name: merk },   
            dataType: "html",  
            success:    function(data)
                {
                    variableArray[merk] = data;
                } 
        }); 
    }
    

    Once all of the retrievals are finished you can access the x and y variables by using variableArray[x] and variableArray[y]

提交回复
热议问题