2014-02-10 104 views

回答

0

使用RhoMobile,您可以使用通常的AJAX方法来访问Web服务来获取或发布数据。

此外,您可以使用Ruby或JavaScript中的RhoMobile Network API来调用Web服务,注册回调。

例如,在Ruby中,你可以有这样的代码在一个控制器:

def getData 
    #Perform an HTTP GET request. 
    getProps = Hash.new 
    getProps['url'] = "http://<my_url>/Json/Server/GetDada?username=admin&password=pass" 
    getProps['headers'] = {"Content-Type" => "application/json"} 
    Rho::Network.get(getProps, url_for(:action => :get_callback)) 
    render :action => :transferring 
end 

def get_callback 
    if @params['status'] == "ok" 
    get_result = Rho::JSON.parse(@params['body']) 

    puts "**** Parsed it" #{@params['body']}" 
    # Do something with the data 
    end 
end