Sunday, July 13, 2014

titanium - updating data in Parse

var url = "https://api.parse.com/1/batch"; // batch function
 var client = Ti.Network.createHTTPClient({
     // function called when the response data is available
     onload : function(e) {
         Ti.API.info("Received text: \n" + this.responseText);
         textarea.value = this.responseText;
         var response = JSON.parse(this.responseText);
         Ti.API.info("Received object: \n" + response);
         //Ti.API.info("Received xml: \n" + this.responseXML);
         //alert('success');
         //popup.close();
         activityIndicator.hide();
         //process(this.responseXML);
     },
     // function called when an error occurs, including a timeout
     onerror : function(e) {
         Ti.API.debug(e.error);
         textarea.value = e.error;
         //alert('error');
         //popup.close();
         activityIndicator.hide();
       
     },
     timeout : 5000  // in milliseconds
 });
 // Prepare the connection.
 client.open("POST", url); // sending data to Parse
 //client.open("GET", url); // getting result from Parse

 // copied from Parse online settings > Application keys
 client.setRequestHeader("X-Parse-Application-Id", "/**** copied from parse.com ****/");
 // copied from Parse online settings > Application keys
  client.setRequestHeader("X-Parse-REST-API-Key", "/**** copied from parse.com ****/");
  client.setRequestHeader("Content-Type", "application/json");
 client.send(JSON.stringify({
     "requests":[
         {
             "method":"PUT",
             "path":"/1/classes/Hello/JKWFuRnf0T",
             "body":{
                 price:99.99
             }
         }
     ]
   
 }));// data to change or update


returned text:
[{"success":{"updatedAt":"2014-07-13T15:57:31.607Z"}}]

No comments: