简体   繁体   中英

How to update specific row in table from Parse.com in Titanium?

I am creating a math quiz using Titanium and Parse.com as my database. So the students will first input their details including student ID which will be stored in the database. Then, they will attempt the questions and their answers will be stored in the database.

I am having trouble posting values to a specific row in table. Currently, when an answer is submitted to the database, a new row will be created.

But what I want to do is whenever there is an answer sent to the database, it will be posted to the row which corresponds to the student's ID.

[To retrieve the student's ID, I use --> var studentNric = Ti.App.Properties.getString('studentNric');]

This is the code that I am using to do the post to the database.

 nextbtn.addEventListener('click', function() { var parseURL = "https://api.parse.com/1/classes/student_submitted_answer"; var ans = ansTextfield.value; var postJson = { question1ans : ans + '' }; var xhr = Ti.Network.createHTTPClient({ onload: function(e) { Ti.API.info(this.responseText);//check what the parse.com send back var responseObject = JSON.parse(this.responseText); }, onerror: function(e) { Ti.API.info(this.responseText); //alert('Error Getting Key Values'); }, timeout:10000 /* in milliseconds */ });//end of HttpClient object creation, xhr. xhr.open("POST", parseURL); xhr.setRequestHeader('X-Parse-Application-Id', 'PyuzSSnK8IvmdvIjlUxlJSLt4HooekKBiGAw1PPr'); xhr.setRequestHeader('X-Parse-REST-API-Key', 'BM2o9tWcxjcHV0TPVayKF78eTF4HV1y3pvX5RQdF'); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(JSON.stringify(postJson)); }) 

Someone help me please? Thanks in advance for your help.

you should be doing a 'PUT' not a 'POST' see the documentation for updating an object

https://parse.com/docs/rest#objects-updating

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