Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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 未调用第二个成功函数中的Ajax函数_Javascript_Jquery_Ajax_Datatables - Fatal编程技术网

Javascript 未调用第二个成功函数中的Ajax函数

Javascript 未调用第二个成功函数中的Ajax函数,javascript,jquery,ajax,datatables,Javascript,Jquery,Ajax,Datatables,我正在使用DataTables库,在这里我需要连续发出AJAX请求。 问题是没有调用第二个Success函数中的AJAX函数。 这是全部代码 $(document).ready(()=>{ $.ajax({ url: 'http://localhost:3000/api/post/getUserData', method: 'post', dataType: 'json', data: { &q

我正在使用
DataTables
库,在这里我需要连续发出
AJAX
请求。 问题是没有调用第二个
Success
函数中的
AJAX
函数。 这是全部代码

$(document).ready(()=>{
    $.ajax({
        url: 'http://localhost:3000/api/post/getUserData',
        method: 'post',
        dataType: 'json',
        data: {
            "email": window.email,
            "token": window.token
        },
        success: function(data){ // <-----------------------FIRST SUCCESS FUNCTION
            let table = $('#datatable').dataTable({
                data: data,
                "autoWidth": true,
                columns: [
                    {'data': 'id'},
                    {'data': 'main'},
                    {'data': 'shrinked'},
                    {'data': 'clicks'},
                    {"data": "id",
                        "render": function ( data, type, row, meta ) {
                            return `<button data-id=${data} onclick="disableThis(event)" class="btn btn-warning">Disable</button>`
                        }
                    },
                    {"data": "id",
                        "render": function ( data, type, row, meta ) {
                            return `<button data-id=${data} onclick="deleteThis(event)" class="btn btn-danger">Delete</button>`
                        }
                    }
                ]
            })
//------------------------------Function to add new Row inside Datatable when Form is submmitted
            $(function () {
                $('#form').bind('submit', function (event) {
                    event.preventDefault();
                    $.ajax({
                        url: 'http://localhost:3000/userShrink',
                        type: 'post',
                        datatype: 'json',
                        data: {
                            fullUrl: $('#Url').val(),
                            email: window.email,
                            token: window.token
                        },
                        success: function () { // <-----------------SECOND SUCCESS FUNCTION (THIS ONE IS NOT EXECUTING)
                            $.ajax({
                                url: 'http://localhost:3000/api/post/getUserData',
                                method: 'post',
                                dataType: 'json',
                                data: {
                                    "email": window.email,
                                    "token": window.token
                                },
                                success: function(data2){
                                    console.log(data2)
                                }
                            })
                        }
                    });
                });
            });
        }
    })
})
在此之后,如果
表单
被提交,它将触发此事件,然后
中的数据成功发布到数据库中

//------------------------------Function to add new Row inside Datatable when Form is submmitted
            $(function () {
                $('#form').bind('submit', function (event) {
                    event.preventDefault();
                    $.ajax({
                        url: 'http://localhost:3000/userShrink',
                        type: 'post',
                        datatype: 'json',
                        data: {
                            fullUrl: $('#Url').val(),
                            email: window.email,
                            token: window.token
                        },
当第二个
success
函数被执行或没有执行时,情况会出错,我需要第二个success函数的原因是将新提交的数据加载到
数据表中

success: function () { // <-----------------SECOND SUCCESS FUNCTION (THIS ONE IS NOT EXECUTING)
                            $.ajax({
                                url: 'http://localhost:3000/api/post/getUserData',
                                method: 'post',
                                dataType: 'json',
                                data: {
                                    "email": window.email,
                                    "token": window.token
                                },
                                success: function(data2){
                                    console.log(data2)
                                }
                            })
                        }
success:function(){/自己修复了它,
这是
立即添加行
功能

$(function () {
    $('#form').bind('submit', async function (event) {
        // using this page stop being refreshing
        event.preventDefault();
        let data = {
            'fullUrl': $('#Url').val(),
            'email': window.email,
            'token': window.token
        }
        let data2 = {
            'email': window.email,
            'token': window.token
        }
        $.post('http://localhost:3000/userShrink', data);
        setTimeout(()=>{
            $.post('http://localhost:3000/api/post/getUserData', data2).done(function (res){
                $('#datatable').DataTable().row.add(res[res.length-1]).draw();
            });
        }, 1000)

    })
});

您是否厌倦了在第一个ajax调用之外移出add row函数?希望这有帮助。是的,我有,但仍然不起作用。从ajax调用中移出第二个success函数back@wiseone我在发帖之前已经试过了,也没用。
$(function () {
    $('#form').bind('submit', async function (event) {
        // using this page stop being refreshing
        event.preventDefault();
        let data = {
            'fullUrl': $('#Url').val(),
            'email': window.email,
            'token': window.token
        }
        let data2 = {
            'email': window.email,
            'token': window.token
        }
        $.post('http://localhost:3000/userShrink', data);
        setTimeout(()=>{
            $.post('http://localhost:3000/api/post/getUserData', data2).done(function (res){
                $('#datatable').DataTable().row.add(res[res.length-1]).draw();
            });
        }, 1000)

    })
});