getRemoteData

This function is used for making background POST/GET requests for remote data

AppMobi.device.getRemoteData(url, requestMethod, requestBody, successCallback, errorCallback)

Description:

This function is used for making background POST/GET requests. It is an alternative to the HTML XMLHttpRequest function.

The url parameter should hold the URL to request the XML data from. The requestMethod must be either "GET" or "POST". The requestBody is unused for a request with the "GET" method (just pass an empty string) and should hold the post data for a "POST" method request in a name=value format separated by ampersands. The successCallback should hold the name of a function with a single parameter holding the data returned from the success. The errorCallback should hold the name of a similar function with a single parameter holding the data returned from the error.

Any line breaks returned from a getRemoteData will be replaced with a string of "\n".

Please note that the callback properties are both strings with the names of the callback functions, not the functions themselves.

Available Platforms:

Parameters:

  • url: The URL of the page to access.
  • requestMethod: The method to use for the page access. This parameter should be either "get" or "post".
  • requestBody: The requestBody is unused for a request with the "GET" method (just pass an empty string) and should hold the post data for a "POST" method request in a name=value format separated by ampersands.
  • successCallback: The successCallback should hold the name of a function with a single parameter holding the data returned from the success.
  • errorCallback: The errorCallback should hold the name of a similar function with a single parameter holding the data returned from the error.

    Example:

    
    //GET method example
    AppMobi.device.getRemoteData("http://twitter.com/statuses/public_timeline.xml", "GET","","success_handler","error_handler");
    
    //POST method example
    AppMobi.device.getRemoteData("http://twitter.com/statuses/public_timeline.xml","POST","E-MAIL=html5tools@intel.com&TEST=1&MAX=0","success_handler","error_handler");
    
    //Example Event Handlers
    function success_handler (data) {  alert("success: " + data); }
    function error_handler(data) {  alert("error: " + data); }
                

    Version:

    This method is available in appMobi Version 3.2.0