CPAINT

CPAINT :: Cross-Platform Asynchronous INterface Toolkit

Developer's Guide : Frontend

Frontend Guide: Pages

introduction
integrating CPAINT
working with CPAINT
using the proxy
non-CPAINT data-sources
browser compatibility tests

Using the Proxy Scripts

If you ever need to access data that's on a different server or domain, you will need to use the proxy scripts to access that data. The reason is simple - by default, browsers will not let the XMLHTTP object (or JavaScript) access data that's on a different server or domain. While this was done to stop cross-site browser hijacking, we created the server-side proxy script to maintain security and give you greater flexibility.

You can also use the proxy utility to retrieve data from remote servers that emit either plain text, XML, or an XML variant (including, but not limited to WSDL/SOAP, HTML, RSS/RDF, and many more). This includes backend functionality on a remote server that uses CPAINT. See considerations and enhanced usage for more information.

A call to a remote server is essentially the same, with a few exceptions.

  1. You will need to know the input parameters of the remote page or server you are calling.
  2. The cpaint2.proxy.??? file will need to be located within your server's web root and accessible by the browser.
  3. Before calling cpaint.call(), you will need to set the cpaint.set_proxy_url() to the location of the cpaint2.proxy.??? file.

If the remote script was implemented using cpaint, you can pass the parameters as you would normally, including the remote_method and args parameters.

Note: You can find out if a remote script was implemented using CPAINT v2.x or above by passing the variable api_query either on the querystring or in the POST data in your browser. (You do not need to specify a value after the variable.) If it does, it will reply with a string in the following format:

CPAINT v[major].[minor].[revision]/[language] v[language version]

major = the major version number (ie: 2)
minor = the minor version number (ie: 0)
revision = the revision or release number (ie: 0)
language = the scripting language used (ie: ASP-VBscript)
language version = the version information of the language in use

Sample URL:
http://localhost/cpaint_v2/cpaint.inc.asp?api_query

Sample Response:
CPAINT v2.0.0/ASP-VBscript

However, if the remote script uses something other than CPAINT, you can ignore the remote_method parameter (best to pass an empty string - '') and to put the data to be passed to the remote script in the args parameter(s). For example, if the remote script expected an argument called query and you wanted to pass the value cpaint, the first args parameter should read query=cpaint. Additional parameters to be passed can be put in additional args parameters.

Here's an example HTML file that utilizes the cpaint proxy to retrieve data from Google.

<html>
  <head>
    <title>google via cpaint</title>
    <script type="text/javascript" src="../../cpaint2.inc.js"></script>
    <script type="text/javascript">
      <!--
      var cp = new cpaint();

      cp.set_transfer_mode('get');
      cp.set_response_type('text');
      cp.set_persistent_connection(false);
      cp.set_async(true);
      cp.set_proxy_url('../../cpaint2.proxy.php');
      cp.set_debug(false);

      function ping() {
        cp.call('http://www.google.com/search', '', response, 'q=' + document.getElementById('query').value, 'hl=en');
        return false;
      }

      function response(result) {
        document.getElementById('response').innerHTML = result;
      }
    //-->
    </script>
  </head>
  <body>

    <form action="#" onSubmit="return ping()">
      <input type="text" id="query" value="" />
      <input type="submit" value="query google" />
    </form>

    <div id="response"></div>

  </body>
</html>

Please visit our sponsors - the money helps maintain the site!