Please note: CPAINT nor this website is under active development. |
Developer's Guide : Frontend
Frontend Guide: Pages
introduction
integrating CPAINT
working with CPAINT
using the proxy
non-CPAINT data-sources
browser compatibility tests
Retrieving Data from Local Sources Not Using CPAINT
If you need to retrieve data from a script that is local to your web page, but does not use CPAINT (another AJAX toolkit or Webservices script, for instance), you can simply set cpaint.set_use_cpaint_api() to false and use the same calling conventions you would as for the proxy script (you do NOT need to set cpaint.set_proxy_url(), as the data will be retrieved directly by the browser).
URL Format
No matter which method you use to retrieve data from the backend, we understand that sometimes the script isn't always available on the default HTTP port (port 80) or that it may require a username and password to access. It may be possible to utilize other protocols, but we have not tested it and at this time will not support it. But please contact us if you feel there is need for improvement.
CPAINT supports the use of alternative port numbers and HTTP basic authentication. Here is the standard format for URLs that we support. Sections in brackets ("[", "]") are not required.
http://[userid:password@]server.domain.tld[:port]/path
XML and plaintext response types combined
As a CPAINT use pointed out, there are situations when you might want to create an XML structure via the CPAINT backend but still need to access that response as plaintext (and not as DOM structure). An example for this would be if you're using CPAINT in conjunction with an XML parser XMLJS (http://xmljs.sourceforge.net/).
To make this possible CPAINT will call your local callback function with two parameters since version 2.0.1.
<script src="cpaint2.inc.js" type="text/javascript"></script> <script type="text/javascript"> <!-- var cp = new cpaint(); cp.set_response_type('XML'); function trigger() { cp.call('xml_backend.asp', 'get_XML', parser); function parser(DOM_struct, XML_source) { /* * do something with either the DOM structure * or the plain XML code available through the * second parameter. */ } //--> </script>
Note that in the above example CPAINT is configured to generate a XML response.
Since CPAINT v2.0.1 the local callback function parser() will be called by CPAINT with two parameters:
- The first parameter will contain the response as defined by cpaint.set_response_type() - in this case a DOM object tree because we have configured CPAINT to use XML.
- The second parameter will always contain the raw plaintext response, regardless of the response type configured. So, for response type TEXT the first parameter will contain the un-escaped text response, while the second parameter will contain the raw response including all escape sequences, e.g. \u0010 for line feeds.
It is important to realize that the second argument in your local callback function is optional. So if you're upgrading your CPAINT library there is no need to re-write your callbacks.