jQuery Ajax error handling, show custom exception messages

前端 未结 21 3083
滥情空心
滥情空心 2020-11-22 01:50

Is there some way I can show custom exception messages as an alert in my jQuery AJAX error message?

For example, if I want to throw an exception on the server side v

21条回答
  •  野的像风
    2020-11-22 02:23

    Throw a new exception on server using:

    Response.StatusCode = 500

    Response.StatusDescription = ex.Message()

    I believe that the StatusDescription is returned to the Ajax call...

    Example:

            Try
    
                Dim file As String = Request.QueryString("file")
    
                If String.IsNullOrEmpty(file) Then Throw New Exception("File does not exist")
    
                Dim sTmpFolder As String = "Temp\" & Session.SessionID.ToString()
    
                sTmpFolder = IO.Path.Combine(Request.PhysicalApplicationPath(), sTmpFolder)
    
                file = IO.Path.Combine(sTmpFolder, file)
    
                If IO.File.Exists(file) Then
    
                    IO.File.Delete(file)
    
                End If
    
            Catch ex As Exception
    
                Response.StatusCode = 500
    
                Response.StatusDescription = ex.Message()
    
            End Try
    

提交回复
热议问题