Maxime
Maxime

Reputation: 1345

POST request: return status reports

I have several google Sheets, and I am looking for a value in one of the sheets.

The user enters the looked up value, and the search is then processed on the server, in an MVC action:

Client side

function findKPI() {
    var lookedUpValue = $('#lookedUpValue').val();
    var sheetIDArray = getSheetIDArray();
    var payload = { sheetIDArray: sheetIDArray, lookedUpValue: lookedUpValue }
    $.post('GetValueSheet', payload)
        .done(function (data) { alert("OK") })
        .fail(function (data) { alert("Error: " + data.responseText) })
}

And server-side:

<HttpPost>
Function GetValueSheet(sheetIDArray As List(Of String), lookedUpValue As String) As ActionResult
    Dim API As New GoogleAPI(Web.HttpContext.Current.Request.PhysicalApplicationPath + "APIKey.json")
    Dim ValuesList As List(Of String)
    For Each sheetID In sheetIDArray
        ValuesList = API.getValuesList(sheetID)
        If ValuesList.Contains(lookedUpValue) Then Return Json(sheetID)
    Next
    Return Json(Nothing)
End Function

There is a great number of sheets to go through and it may take a while to process.

I would like to find out if and how it is possible to send intermediate results to the client, to display that 10, 50, etc. % of the sheets have been processed.

Thank you for your help

Upvotes: 1

Views: 51

Answers (1)

TheCog19
TheCog19

Reputation: 1209

Post requests are a discrete transaction, so you can't do it directly. The way I might do this, is to expose an API point that takes an unique key identifying the transaction, when that API point is queried it sends back a response revealing the status of the query.

Doing it in a non-api way, you might try doing it with websockets, which allow two way communication between a client and a server.

Upvotes: 2

Related Questions