Store ajax result in jQuery variable

前端 未结 2 1962
盖世英雄少女心
盖世英雄少女心 2021-01-03 05:19

I started using jQuery and ajax to get data from database, but i cant find out how i can save result of $.get() into variable outside callback function.

This is my j

2条回答
  •  不知归路
    2021-01-03 05:57

    Try this:

    var result = "";
    $.get("test.php", function (data) {
        SomeFunction(data);
    });
    
    function SomeFunction(data) {
        result = data;
        alert(result);
    }
    

提交回复
热议问题