問題描述:
我寫的js方法:
function getname(code){ var name $.post("",{ code:code },function(resurlt){ name=resurlt; }) return name; }
調用的時候,確認返回 resurlt值是正確的,但是return的值為undefined。
產生原因:是Jquery的ajax是異步的,所以大多時候沒執行完AJAX就return htmlcontent了,所以會一直返回undefined,
解決方式:添加async: false,即修改此方法為同步
解決博客地址:https://www.cnblogs.com/hannover/p/4227677.html