<分区>
Possible Duplicate:
Use variable outside the success function from an ajax/jquery call
我有这段代码,但我不明白为什么 html 元素的访问只在 ajax 成功函数中起作用。表单是从 ajax 中提取的,但只有当我将所有元素的选择都放在 ajax 函数中时,我才能访问它。
console.log('submit clicked');
not 以这种方式触发,但在“ajax 成功”中它确实触发了,我认为一切都与ajax 是 DOM 的一部分?
jQuery(document).ready(function($) {
console.log('ready');
$.ajax({
type: 'GET',
url: 'admin-ajax.php',
data: { action: 'get_arve_form' },
success: function(response){
// var table = $(response).find('table');
$(response).appendTo('body').hide();
console.log('response');
[ if i move the code below this ajax function in here its workign fine why not outside of it?]
}
});
// handles the click event of the submit button
$('#mygallery-submit').click(function(){
console.log('submit clicked');
[...]
});