[Solved]Atomic Operation not working



  • I cannot get the atomic update operation to work in enginio.

    @
    var url = "https://api.engin.io/v1/objects/student/541be64be5bde564f504ca2e/atomic";

            var xhr = new XMLHttpRequest();
    
            xhr.onreadystatechange = function() {
                if ( xhr.readyState == xhr.DONE)
                {
                    console.log("Success " + xhr.responseText + " STATUS " + xhr.status)
                    if ( xhr.status == 200)
                    {
                        var jsonObject = JSON.parse(xhr.responseText); // Parse Json Response from http request
                        console.log("Success " + jsonObject.balance)
                    }
                }
            }
    
            xhr.open("PUT",url,true);
    
            var data = {
                "$inc": {
                    "balance": 1
                }
            }
            xhr.setRequestHeader("Enginio-Backend-Id", "BACKENDID")
            xhr.send(data);@
    

    This returns
    qml: Success {"errors":[{"reason":"ParseError","message":"Cannot parse request body as json"}]} STATUS 400

    When tested with html also says the same.


  • cid:52:privileges:purge

    It seems that you are not sending a valid JSON to Enginio.

    This should fix it:
    @
    xhr.send(JSON.stringify(data));
    @



  • Thanks. It worked.

    Also a related question, is there a way to atomically update object from qml. If yes - how? If no - is it planned?

    I am using Qt 5.3.2.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.