如下,即可将d中的值赋给外部变量
//把ajax的异步设置成同步,防止$.getJSON无法对外部变量进行赋值,必须在$.getJson前面 $.ajaxSetup({async:false}); $.getJSON('http://xxx', function(d) { xxx });