CPAINT :: Cross-Platform Asynchronous INterface Toolkit

Please note: CPAINT nor this website is under active development.

Upgrade: Frontend Changes

Because CPAINT v2.x is completely object-oriented, the first thing you must do is create an instance of the cpaint object and set any options (set_async(), set_debug(), set_persistent_connection(), set_proxy_url(), set_response_type(), and set_transfer_mode()) if you do not wish to use the defaults. You can create the cpaint object inside or outside of your primary JavaScript function, depending on whether or not you want to reuse the object for other backend calls or need to make multiple calls to the JavaScript function.

Here is a CPAINT v1.x call in JavaScript and it's equivalent in CPAINT v2.x.

v1.x

function doAdd() {
  cpaint_call('calculator.asp', 'GET', 'addNumbers',
    document.getElementById('num1').value,
    document.getElementById('num2').value, updateResults, 'TEXT'
  );
}

function updateResults(calculatorResults) {
  document.getElementById('answer').value = calculatorResults;
}

v2.x

var cp = new cpaint();
cp.set_transfer_mode('get');

function doAdd() {
  cp.call('calculator.asp', 'add', response, document.getElementById('num1').value,
    document.getElementById('num2').value
  );
}

function response(result) {
  document.getElementById('result').value = result.ajaxResponse[0].data;
}

In addition, the parameters that cpaint.call() accepts is shorter for improved readability and for reuse of the cpaint object. See the reference for the exact parameter list.

Finally, if you utilize the proxy utility, you no longer have a separate call. For example, these two code blocks pass a query to Google and retrieve the results:

v1.x

cpaint_get_remote_file('cpaint_proxy.asp', 'http://www.google.com/search', 'GET',
  'TEXT', googleSearchResults, 'q', 'CPAINT', 'hl', 'en'
);

v2.x

var cp = new cpaint();
cp.set_transfer_mode('get');
cp.set_response_type('text');
cp.set_proxy_url('../../cpaint2_proxy.php');

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

function response(result) {
  document.getElementById('response').innerHTML = result;
}