简体   繁体   中英

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?

Possible solutions I came up with:

  • having the data stored in the session for later submission (data is lost if session expired)
  • have the data downloaded by the user and manually submit it again
  • is it possible to store the data as cookie?

Yes, You can store data at cookie.
Or you can store data by ajax before your 'real' data submit.

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM