问题描述:
我写的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