Loading Remote Data via AJAX/JSONP

PHP Autocomplete supports loading remote data on the same or difference domain through AJAX. The remote data must be in JSONP format. JSONP is “JSON with padding“, a JSON derivative, used to retrieve JSON across domains.

Select2 has excellent remote data support. PHP Autocomplete goes one step further to make the routine even easier to implement with load_remote_data() method. The method take one parameter that is the URL to the JSONP remote data. As easy as pie. The URL can be either from a local or a remote domain.

<?php
$pac = new C_PhpAutocomplete('remote_data');
$pac -> load_remote_data('http://example.com/phpAutocomplete/examples/sample_remote_data.php');
$pac -> set_placeholder('Enter name');
$pac -> display();
?>
<input id="remote_data" type="hidden" />

File (Remote sample data) must be the following JSONP format.

[ {"id": "1", "text": "BOBA FETT"},{"id": "2", "text": "R2D2"},{"id": "3", "text": "JAR JAR BINKS"} ]

No related content found.

Tags: , , ,