简体   繁体   English

如何在客户端处理HTTP错误?

[英]How to handle HTTP error in the client side?

What is the best way to handle HTTP errors (404, 503, etc.) when submitting a crucial data on the server? 在服务器上提交关键data时,处理HTTP错误(404、503等)的最佳方法是什么?

Possible solutions I came up with: 我想出了可能的解决方案:

  • having the data stored in the session for later submission (data is lost if session expired) data存储在session以供以后提交(如果会话过期,数据将丢失)
  • have the data downloaded by the user and manually submit it again 由用户下载data并再次手动提交
  • is it possible to store the data as cookie? 是否可以将data存储为cookie?

Yes, You can store data at cookie. 是的,您可以将数据存储在cookie中。
Or you can store data by ajax before your 'real' data submit. 或者,您也可以在提交“真实”数据之前通过ajax存储数据。

like this .. 像这样 ..

function doSubmit() {

    // It will store the crucial data at server side.
    try {
        $.ajax({
           ...
           url : /temporary/storeData.do,
           data : {
                      // Your crucial data will be located here.
                  },
           ...
        });
    } catch (e) {
        // Error Handling for '$.ajax.error'.
        return;
    }

    // It's your real submit.
    document.aform.submit();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何处理 Kendo 网格中的客户端错误处理 - How to handle client side Error handling in Kendo grid 通过排队机制处理离线http请求客户端 - Handle offline http request client-side via queuing mechanism 在服务器端禁用aspxgridviews,如何在客户端处理? - Disabling aspxgridviews on server-side, how to handle on client-side? 如果客户端从客户端更改了某些数据属性,如何处理? - How to handle if a client change some data attributes from the client side? 如何从客户端的Telerik UI处理radgrid中的expandcollapse? - How to handle expandcollapse in radgrid from Telerik UI on the client side? 如何在代码后面处理客户端确认? - How to handle client-side confirm in code behind? 如何使用node.js处理客户端路由? - How to handle client side routing with node.js? 服务器端控制器如何处理来自客户端的多个会话? - How server-side controllers handle multiple sessions from client? 如何在客户端 Express 应用程序中处理 jwt 令牌和 refreshtoken? - How to handle jwt token and refreshtoken in a client side express application? 如何处理对客户端反应应用程序的外部重定向? - How do I handle external redirects to a client side react app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM