Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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 另一个';s成功(jQuery)_Javascript_Jquery_Html_Ajax_Xmlhttprequest - Fatal编程技术网

Javascript 另一个';s成功(jQuery)

Javascript 另一个';s成功(jQuery),javascript,jquery,html,ajax,xmlhttprequest,Javascript,Jquery,Html,Ajax,Xmlhttprequest,我想在成功后运行另一个ajax请求 代码 我的问题是为什么这段代码不起作用,以及如何使它起作用 它应该会起作用。您是否收到错误?听起来第二个ajax请求没有成功返回。试着设置一个错误处理程序,看看出了什么问题。@Barmar我没有收到任何错误如果你没有成功,你就会收到错误。添加错误处理程序并调试代码。这不是有效的json。 $(document).ready(function(){ $('*[data-load-template]').each( function () {

我想在成功后运行另一个ajax请求

代码
我的问题是为什么这段代码不起作用,以及如何使它起作用

它应该会起作用。您是否收到错误?听起来第二个ajax请求没有成功返回。试着设置一个
错误处理程序,看看出了什么问题。@Barmar我没有收到任何错误如果你没有成功,你就会收到错误。添加错误处理程序并调试代码。这不是有效的json。
$(document).ready(function(){

    $('*[data-load-template]').each( function () {

        var template = $(this).data('load-template');
        var element = $(this);

        $.ajax({
            url     : "templates/" + template + '.tpl',
            method  : "GET",
            success : function (htmlData) {
                $.ajax({
                    url     : "data/" + template + '.json',
                    method  : "GET",
                    success : function (jsonData) {
                        console.log(jsonData); // why isn't this one working???
                    }       

                });
                element.html(htmlData); // this is working
            }

        });

    });

}); // dom ready event