why cant I return data from $.post (jquery)

前端 未结 6 2461
南旧
南旧 2020-12-19 05:39

I must be making a silly mistake but I cannot return the data I get from a $.post function and store it in a variable, not only that, I cannot return ANYTHING from within th

6条回答
  •  半阙折子戏
    2020-12-19 06:16

    Try using the .done() to execute the returned data. This should ensure that it gets the data and doesn't set your variable or alert data before it finishes.

    $.post("demo_test_post.asp", { name: "Donald Duck", city: "Duckburg" })
    .done(function(data) {
      alert("Data Loaded: " + data);
      //Or return data;
    });
    

提交回复
热议问题