1
var args = arguments[0] || {};
$.atn.text=args.attendance;
Ti.API.info('attendance:'+args.attendance);
function doClick(e){
  $.atn.value=$.atn.value+1;
  Ti.API.info('atn is'+$.atn.value);

  var url = "api.usergrid.com/PRI_95616/LOGIN/attendances?";

  var client = Ti.Network.createHTTPClient({
    onload : function(e) {},

    onerror : function(e) {
      Ti.API.debug(e.error);
      alert('error');
    },
    timeout : 5000  // in milliseconds
  });
  client.setRequestHeader('content-type', 'JSON');
  client.open("PUT", url);

  client.send(JSON.stringify(jsonobject));
}

我想获取然后更新出勤值,然后在数据库中插入更新的值。我该怎么做?

4

1 回答 1

1

If by "update the database" you mean PUT to the Restful API, then you have one small error.

client.send(JSON.stringify(jsonobject));

jsonobject is not defined. It must be the json (JavaScript) object you just built. if $.atn is the object you're pushing values into then try:

client.send(JSON.stringify($.atn));

I don't know the REST API specs for usergrid.com, but if all you have to do is PUT a json object with .text and .value defined, the URL "api.usergrid.com/PRI_95616/LOGIN/attendances?" then this should do it. However, you'll have to put http:// before the URL like:

"http://api.usergrid.com/PRI_95616/LOGIN/attendances?"

于 2015-03-12T00:57:25.907 回答