lecms开发踩过的坑,$.ajax异步请求一直进入error

lecms开发踩过的坑,$.ajax异步请求一直进入error

来源:帝国CMS模板网 作者:静谧 时间:2026-07-05
浏览:34 收藏 点赞(0)
简介:function daoru(order, to, cid, page) { setTimeout(function() { $.ajax({ url: 'index.php?douhaoai_admin-import_title_by_order-ajax-1', type: 'POST', data: { p: page, order: order, to: to, cid: cid }, dataType: 'json', success: function(result) { if (loadIn
function daoru(order, to, cid, page) {
            setTimeout(function() {
                    $.ajax({
                        url: 'index.php?douhaoai_admin-import_title_by_order-ajax-1',
                        type: 'POST',
                        data: {
                            p: page,
                            order: order,
                            to: to,
                            cid: cid
                        },
                        dataType: 'json',
                        success: function(result) {
                            if (loadIndex) { // 检查loadIndex是否存在
                                layer.close(loadIndex); // 关闭加载提示
                                loadIndex = null; // 重置为null,避免重复关闭
                            }
                            var result = toJson(result);
                            if (result.msg == 1) {
                                if (page == 1) {
                                    layer.open({
                                        type: 1,
                                        area: ['500px', '150px'],
                                        title: false,
                                        btn: '停止导入',
                                        btnAlign: 'c',
                                        closeBtn: 1,
                                        shade: 0.6,
                                        shadeClose: true,
                                        content: '<div id="msgtxt" style="text-align:center;line-height: 50px;">' + result.status + '</div>',
                                        btn1: function(index, layero, that) {
                                            location.reload()
                                        },
                                        cancel: function() {
                                            location.reload()
                                        }
                                    });
                                }
                                if (page > 1) {
                                    $('#msgtxt').html(result.status);
                                }
                                page++;
                                daoru(order, to, cid, page);
                            } else {
                                layer.msg(result.status, {
                                        icon: result.msg,
                                        shade: .6
                                    },
                                    function() {
                                        location.reload()
                                    });
                            }

                        },
                        error: function(jqXHR, textStatus, errorThrown) {
                            alert('error');
                        }
                    });
                },
                1000);
        }

发起了请求,但是不进入success,进入error,服务端响应数据如下:

开始一直没在意第二行的这个信息~~~

服务端代码部分截图如下:

最开始没有加 exit; 之前用习惯了lecms的E函数。

坑点:

在echo后面必须加上 exit;或者 die; 来结束!!!

在线
客服