2014-02-10 46 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