簡體   English   中英

如何使用XmlHttpRequest和ASP.NET MVC處理文件上傳錯誤?

[英]How to deal file upload error with XmlHttpRequest and asp.net mvc?

為簡單起見:

客戶:

var xrh = new XmlHttpRequest();
...
xrh.onerror = on_upload_error;
xrh.send(...)

服務器:

public class file_transfer
{
    [HttpPost]
    public void Upload(HttpPostedFileBase[] files_to_upload)
    {
        ...
        if (succeeded)
        {
            // what should I to to let the client know the success? in onload
        }
        else
        {
            // what should I to to let the client know the failaure? maybe in onerror
        }
    }
}

我應該如何讓客戶知道成功? 在加載?

我應該如何讓客戶知道失敗的原因? 也許陷入錯誤?

您可以將http成功/失敗的代碼返回給客戶端:

[HttpPost]
public ActionResult Upload(HttpPostedFileBase[] files_to_upload)
{
    ...
    if (succeeded)
    {
        return new HttpStatusCodeResult(200);
    }
    else
    {
        return new HttpStatusCodeResult(400);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM