Re: [ js ] 有關 function return string的問題
試試看這樣子
function accountCheck(a,callback) {
// ....
//
$.post('fetch.php', /* ... */ , function(data) {
callback(data);
});
}
$('#register_submit').click(function(){
var acc = $('#register_account').val();
accountCheck( acc, function(result) {
alert(result);
});
});
※ 引述《ot32em (reverse(wasefo);)》之銘言:
: $(document).ready(function(){
: ...
: function accountCheck(a){
: if( a.length < 3 ) return 'short';
: if( a.length > 11) return 'long';
: $.post('fetch.php', { "type":"ncuaccount", "email": 'someemail'
: , "week": '30'}
: , function(data){ alert(data);return data; } );
: }
: 綠色的可以回傳資料
: 可是在下面我alert result時
: 卻是undefined or 空字串
: 這會是因為.post要等 然後 function accoutnCheck(a) 等不及就return的關係嗎?
: $('#register_submit').click(function(){
: var acc = $('#register_account').val();
: var result = "";
: result = accountCheck( acc );
: alert(result);
: ...
: });
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 115.64.54.125
推
05/09 17:24, , 1F
05/09 17:24, 1F
→
05/09 17:25, , 2F
05/09 17:25, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):