1. 程式人生 > >ajax 函數外調用

ajax 函數外調用

src -s .ajax ava html return data- log logs

 1 <html data-dpr="1" style="font-size: 50px;">
 2 
 3 <head>
 4 
 5 <script src="js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
 6 </head>
 7 
 8 <body style="">
 9 
10 <script type="text/javascript">
11 var id = "123";
12 $.ajax({
13 url: ‘http://ai2800.com/api.php/Goods/type_goods/type/xsgss‘,
14 type: ‘post‘, 15 dataType: "json", 16 // data:{wurl:w_url,murl:m_url}, 17 async: false, 18 error: function() {}, 19 success: function(data) { 20 id = data; 21 console.log(id) 22 23 } 24 }) 25 26 console.log(id); 27 </script> 28 29 30 31 32 <script type="text/javascript"> 33 function
load(val) { 34 $.ajax({ 35 url: ‘http://ai2800.com/api.php/Goods/type_goods/type/xsgss‘, 36 type: ‘post‘, 37 dataType: "json", 38 // data:{wurl:w_url,murl:m_url}, 39 async: false, 40 error: function() {}, 41 success: function(dat) { 42 id = dat; 43 val(dat) 44 45 } 46 }) 47 } 48 load(function(data) { 49 console.log(data)
50 }) 51 </script> 52 53 54 <script type="text/javascript"> 55 function s() { 56 var id 57 $.ajax({ 58 url: ‘http://ai2800.com/api.php/Goods/type_goods/type/xsgss‘, 59 type: ‘post‘, 60 dataType: "json", 61 async: false, 62 error: function() {}, 63 success: function(dat) { 64 id = dat; 65 } 66 }) 67 return id; 68 } 69 var b = s() 70 console.log(b) 71 </script> 72 73 74 <script type="text/javascript"> 75 var id 76 $.ajax({ 77 url: ‘http://ai2800.com/api.php/Goods/type_goods/type/xsgss‘, 78 type: ‘post‘, 79 dataType: "json", 80 async: false, 81 error: function() {}, 82 success: function(dat) { 83 var id = dat; 84 bb() 85 } 86 }) 87 88 function bb() { 89 console.log(id) 90 } 91 </script> 92 93 </body> 94 95 </html>

ajax 函數外調用