我有下面的代碼從AJAX請求中獲取一些html,然後隱藏表中的一行並顯示另一個,但即使我創建的var
用於存放html(quick_edit_html )在AJAX函數運行後(通過將其放入警告框中進行測試)可用時,Firebug告訴我,當我嘗試在下一個函數中使用它時,它不存在(在AJAX請求完成之前它不會運行) 。AJAX/jQuery-var不存在
關於我要去哪裏的任何想法都是錯誤的?
/** Run the AJAX request to grab the qucik edit html */
var load_quick_edit = jQuery.post(MyAjax.ajaxurl, data, function(response){
var quick_edit_html = response;
});
/** Display the correct quick edit row */
load_quick_edit.done(function(){
/** Hide the row that is to be edited */
jQuery('tr#display-'+slug).hide();
/** Show the quick edit row that the user has requested */
jQuery('tr#quick-edit-'+slug).show();
jQuery('tr#quick-edit-'+slug).html(quick_edit_html);
});
謝謝。
謝謝 - 以爲它會有點愚蠢! – 2011-12-22 15:18:01