return responseText from jQuery.get()

后端 未结 4 891
粉色の甜心
粉色の甜心 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:42

    You can always use:

    var msg;
    $.get("my_script.php", function(text) {
      msg = text;
    });
    

    If for some reason the response is text, the remote script might be changing the content-type to something like JSON, and thus jQuery tries to parse the string before outputting to you.

提交回复
热议问题