【发布时间】:2013-01-13 10:35:06
【问题描述】:
可能重复:
Use variable outside the success function from an ajax/jquery call
我有这段代码,但我不明白为什么 html 元素的访问只能在 ajax 成功函数内部工作。无论哪种方式,表单都是从 ajax 拉入的,但只有当我将所有对它的元素的选择放在 ajax 函数中时,我才能访问它。
console.log('submit clicked'); 以这种方式不触发,但在“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');
[...]
});
【问题讨论】:
-
如果您发布了“不起作用”的代码并解释了具体不起作用的代码,这将有所帮助。
-
@AaronKurtzhals 我确实做到了!
标签: javascript jquery ajax forms wordpress