ajax long connection return data cannot enter success status is cancelled

Front end implementation:

function ajaxLongConn(){
                type : "POST",//
                //Async: true, / / synchronous execution
                timeout :180000,//The single timeout long connection time is three minutes
                url : "${ctx}/pollModel/timerPollReport.html",
                dataType : "json", //Return data in the form of json
                success : function(result) {
                    //Requests succeed without recursion, and the entire web life cycle will succeed only once
                    var data = result.poll_report;
                    //alert("result:" + result);
                    popMsg(data.pollTime,data.pollId,data.totalPoll, data.errPresent, data.errTotal);
                    ajaxLongConn(); // Recursive call to prevent patrol time from changing
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") { // request timeout
                        ajaxLongConn(); // Recursive call
                        // Other errors, such as network errors
                    } /*  else {
                    }  */

Background code:

private static Boolean poll_flag = false;//Pop up ID
    private static int pollCounter;
    @RequestMapping(value = "/timerPollReport", produces = "text/html;charset=UTF-8;")
    public @ResponseBody String timerPollReport(){
        Map<String,Object> report;
        String nowDate;
        while (true) {
            try {
                nowDate = DateUtil.toDate(new Date(),"HH:mm");
                //If the patrol ID is marked as not patrol
                if(pollCounter == 0)
                    pollCounter = PollCron.poll_count;
                if(pollCounter != PollCron.poll_count) {
                    poll_flag = false;//If the patrol is reset, the pop-up id also needs to be reset
                    pollCounter = PollCron.poll_count;
                if (!StringUtils.isNull(PollCron.sendReport) && nowDate.compareTo(PollCron.sendReport) > 0 && PollCron.isPoll && !poll_flag) {
                    poll_flag = true;//Ejected, waiting for next reset
                    report = PollCron.reportMap;
                    System.out.println("Send patrol Report~~~~");
                Thread.sleep(30000);//Prevent too frequent sequence
            } catch (InterruptedException e) {
        return JsonUtil.objToJson(report);

The background has met the conditions and called return JsonUtil.objToJson(report); however, the front end does not execute the code in success.
Open F12 and find that the status of timerPollReport.html is called.
So it is speculated that because the requested link has been terminated at the front end, the link owned at the moment does not match the link returning data, and all the success methods cannot be executed.
terms of settlement:
1. Change ajax type: "POST" to GET.
2. Extend the timeout time of ajax

Tags: JSON network

Posted on Sun, 03 May 2020 23:57:03 -0700 by webmaster02