weixin_33670786 2017-03-02 20:35 采纳率: 0%
浏览 17

Ajax超时问题

We have an application that's built using MVC/Knockout js. At the end of the form when the user goes to submit all of the data is turned into a json string and is sent through Jquery.ajax to our controller. Once it reaches there it will perform any validation returning the string "done" once the database commits are finished (if there are no issues). The ajax callback will set a variable with that done status and submit a final form containing that status, where if the status string isn't passed in as "done" error message will display which a handful of users have been seeing.

My question is does anyone know of any edge cases that could be causing the response not to return anything other than "done" (excluding validation errors or any exceptions which are logged by elmah). The validation step will throw an error that will return to elmah at any point where the data is invalid which hasn't happened yet (elmah has recorded other issues). For 99% of users there is no issue so I'm trying to figure out if there is some edge case I'm missing.

Below is my AJAX request, the data is built using the knockout plugin knockout.mapping then JSON.stringify. The one user we've heard back from is using internet explorer 11 (I'm unable to reproduce the error in my copy). Originally the timeout was 10 seconds, we've bumped it up to 30 which seemed to help (setting it to 1ms would return an empty string). One of the biggest issues with debugging the issue is that the data is anonymous so it's hard to tie an error back to any user.

        $.ajax({
            url: util.baseUrl('/Survey/Form'),
            type: "POST",
            data: dataStr,
            contentType: "application/json; charset=utf-8",
            timeout: 30000
        })
        .done(function (status) {
            if (status === "done") {
                self.gotoDonePage(status);
            } else {
                self.gotoDonePage(status);
            }
        })
        .fail(function (err) {
            self.gotoDonePage(status);
        })
        .always(function () {
            layoutSetup.hideSpinner();
        });

The data is anonymous, so we're only able to see where it came from but nothing else. The issue I'm having is the form submission that's done directly after this through the gotoDonePage method is passing a status other than "done". The validation is set up so that any errors at all, or invalid data will be caught by elmah which isn't happening. My theory is that the status that's being returned is an empty space or has extra spaces due to some issue. It could also be that the request is taking longer than 30 seconds to complete but it doesn't seem likely based on what I've experienced.

The gotoDonePage function is basically

self.gotoDonePage = function (status) {
    var url = util.baseUrl('/Survey/Done');
    var form = $('<form action="' + url + '" method="post">' +
        '<input type="hidden" name="status" value="' + status + '" />' +
        '<input type="hidden" name="surveyTypeCd" value="' + self.SchoolSurveyTypeCd() + '" />' +
        '<input type="hidden" name="surveyName" value="' + self.SchoolSurveyNameTxt() + '" />' +
        '<input type="hidden" name="schoolYear" value="' + self.SchoolYear() + '" />' +
        '<input type="hidden" name="schoolName" value="' + $('#SchoolName').val() + '" />' +
      '</form>');
    $('body').append(form);
    form.submit();
}

When the done page is returned there is just a simple razor if else to determine if it got the string of "done" and if not display the message.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?