return responseText from jQuery.get()

后端 未结 4 890
粉色の甜心
粉色の甜心 2020-12-10 03:58

I tried to do something like this :

var msg = $.get(\"my_script.php\");

I thought msg would be set to the text returned by my_script.php,i.

4条回答
  •  一整个雨季
    2020-12-10 04:37

    After some testing, I ended up finding a solution.

    I need the call to be synchronous, $.get shorthand function is always asynchonous, so I will need to use $.ajax, like this:

    var msg = $.ajax({type: "GET", url: "my_script.php", async: false}).responseText;
    

    I don't think there is a better way to do this, thanks for your answers.

提交回复
热议问题