2010-08-03 91 views
0

遇到問題我有這個功能傳遞變量在jQuery函數

function procData(a) { 
    $('#loading' + a).show(); 
    $.post("ajax.php?talk=" + a, { 
     slot: $('#slot' + a).val() 
    }, function (response) { 
     $('#talkdesc' + a).fadeOut(); 
     setTimeout("finishAjax('talkdesc', a, '" + escape(response) + "')", 400); 
    }); 
} 

function finishAjax(id, a, response) { 
    $('#' + id + a).html(unescape(response)); 
    $('#' + id + a).fadeIn(); 
} 

在procData(),我想傳遞變量「a」到finishAjax,但似乎沒有任何工作。它在除了這個之外的所有被調用的區域都可以工作。有任何想法嗎?

回答

1
setTimeout(function() { 
    finishAjax('talkdesc', a, escape(response)); 
}, 400); 
+1

恐怖!不要將字符串傳遞給'setTimeout'。我將修改您的答案以使用匿名功能。 – 2010-08-03 05:06:44

+0

@熊感謝! – Amarghosh 2010-08-03 09:58:37