Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

Fetching content from remote server using Rest Api adapter

$
0
0

Hi Friends,

I am very new to alloy and titanium, we have an app which was built using titanium default template. i would like to change this to alloy template

Following is code which used to fetch content from remote server in default template project

xhr.open("POST","http://xxxxxxxxx/api/login/");//ADD your URL
    xhr.setRequestHeader("Set-Cookie", "application/json");
    var param={ "username":'myusernamwe',"password":'mypassword","api":true,"type":'P' };
    Ti.API.info('Params'+JSON.stringify(param));
    xhr.send(param);
    xhr.onload = function(){
        var jsonValue = JSON.parse(this.responseText);
        cookie = this.getResponseHeader('Set-Cookie');
In my alloy project i would like to use rest api adapter method to fetch content from remote server.

please see my restapi.js , model and controller file below

click here to see restapi.js

my model is

exports.definition = {
    config : {
        "debug":1, 
        "url" : "http://xxxxxxxxxxx.com/api/login/",
 
        "columns" : {
 
        },
        "adapter" : {
            "type" : "restapi",
            "collection_name" : "threadShow"
            }
        },
 
    extendModel : function(Model) {
 
        _.extend(Model.prototype, {
            url : function() {
 
                //alert(this.get(id))
                return "http://xxxxxxxxxx.com/api/login/"
                },
                parse : function(_resp) { debugger;
 
                    var model = this;
                   alert(model);
                  // alert(_resp);
 
 
                    return _resp;
                    }
                });
 
                return Model;
        },
    extendCollection : function(Collection) {
        _.extend(Collection.prototype, {
            url : function() {
                return "http://xxxxx.com/api/login/"
            },
            parse : function(_resp) { debugger;
 
                var model = this;
                return _resp.model;
            }
        });
       // alert(2);
        return Collection;
    }
}
and my controller is
var book = Alloy.createModel('threadShow');
 
var test=book.fetch();
 
alert (test);

My problem is i didn't get any value in controller (in test variable),

any one please help me


Viewing all articles
Browse latest Browse all 7655

Trending Articles