作者supercygnus (......)
看板Ajax
標題[問題] angularjs $http函數問題
時間Tue Jun 6 01:12:36 2017
我寫了一個$http函數去nodejs取得東西
程式如下
https://codepaste.net/94g4gx
要怎麼取得then()回調函數中從後端取回的東西
我程式中r=tmp是無效的
r是undefine
到底要怎麼取得
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.177.44.226
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Ajax/M.1496682760.A.7D7.html
1F:→ chihlee5566: Postman測試有東西嗎? 06/06 09:12
2F:→ supercygnus: 有東西 06/06 09:47
3F:→ Kenqr: tmp的值是正確的嗎? $http是非同步操作 你是在哪讀取r的值? 06/06 10:17
4F:→ supercygnus: Tmp的值是正確的,我有印出來看過,我是想在function 06/06 13:57
5F:→ supercygnus: 外面用tmp 06/06 13:57
6F:→ supercygnus: 但是卻沒辦法把tmp 的值往外送,r=tmp是無效的,最 06/06 13:59
7F:→ supercygnus: 候r是undefined 06/06 13:59
8F:→ dannypsnl: 因為那是非同步的,你的r在r=tmp之前就被印出來了,當 06/06 14:42
9F:→ dannypsnl: 然是undefined 06/06 14:42
10F:→ supercygnus: 是喔,那要怎麼變同步? 06/06 16:02
12F:→ supercygnus: 04757.html 06/06 16:18