Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript I';我对我在这里可以做的事情的范围感到困惑,Jquery_Javascript_Jquery_Javascript Events - Fatal编程技术网

Javascript I';我对我在这里可以做的事情的范围感到困惑,Jquery

Javascript I';我对我在这里可以做的事情的范围感到困惑,Jquery,javascript,jquery,javascript-events,Javascript,Jquery,Javascript Events,我正在尝试在每个问题提交后加载一个新的问题表单,我正在加载文档准备中的第一个问题。但是我不确定是否应该在ajax表单请求范围内加载第二个,也不确定之后加载问题的范围。。还是js的新手。:) 代码如下: $(document).ready(function() { $.ajax({ url : baseUrl + 'online_test/loadQuestion', cache : false, success : function(htm

我正在尝试在每个问题提交后加载一个新的问题表单,我正在加载文档准备中的第一个问题。但是我不确定是否应该在ajax表单请求范围内加载第二个,也不确定之后加载问题的范围。。还是js的新手。:)

代码如下:

$(document).ready(function() {
    $.ajax({
        url : baseUrl + 'online_test/loadQuestion',
        cache : false,
        success : function(html) {
            $("#question").html(html); // Insert newx question
            $('.dummy_answers').hide();
            $('.button_next').click(function() {
            $(this).parent().children('.dummy_answers').show();
            bSubmit = $('<button name="Submit" type="button" class="submit_button" value="Submit">Submit</button>');
            $(this).parent().children('button').replaceWith(bSubmit);
            bSubmit.click(function(){
                var new_url = baseUrl + 'online_test/create_question';
                $.post(new_url, function(data) {
                      //Fade Out The Current Question
                       $('#question').fadeOut('slow');
                      //Get and Fade In/Put the previous question into the created question block

                      //Load the next uncreated question
                       $.ajax({
                            url : baseUrl + 'online_test/loadQuestion',
                            cache : false,
                            success : function(html) {
                                $('#question').hide();
                                $("#question").html(html);
                                $('.dummy_answers').hide();
                                $('#question').fadeIn('slow');
                            }
                       });
                     });

            });

            });

        },
    });

});
$(文档).ready(函数(){
$.ajax({
url:baseUrl+“在线测试/加载问题”,
cache:false,
成功:函数(html){
$(“#问题”).html(html);//插入新的问题
$('.dummy_answers').hide();
$('.button_next')。单击(函数(){
$(this.parent().children('.dummy_answers').show();
b提交=$('Submit');
$(this.parent().children('button').replaceWith(bSubmit);
b submit.click(函数(){
var new_url=baseUrl+“在线测试/创建问题”;
$.post(新url,函数(数据){
//淡出当前的问题
$('问题').fadeOut('慢');
//获取并淡入/将上一个问题放入已创建的问题块中
//加载下一个未创建的问题
$.ajax({
url:baseUrl+“在线测试/加载问题”,
cache:false,
成功:函数(html){
$('问题').hide();
$(“#问题”).html(html);
$('.dummy_answers').hide();
$('question').fadeIn('slow');
}
});
});
});
});
},
});
});

为什么不尝试在ajax外部定义的ajax内部调用函数呢?

我确实考虑过这一点,但认为这是一种不好的做法。但是,这不会使我处于特定ajax调用的范围内吗?如果这是一个愚蠢的问题,请道歉。:)几分钟前,我做了同样的事情,它按照预期的方式工作。也许这并不明智,但如果仅限于这段代码,这肯定不是一个坏的做法。