The search results are sent as a result table to the callback function whose name you specified at the time of the call.
In our example, we must therefore create a JavaScript function "callback1" that will display the results. Only one parameter is sent to this function: an array of companies where each company is a dictionary containing the keys:
- ref: Unique company number;
- name: Company name;
- zip: Zip code;
- city: city.
The "ref" parameter is important because it is the number that will be used to retrieve the detailed information of the company.
Implementation example of the callback function:
function callback1(data) {
var line;
var html = '<table><tr><th>Nom</th><th>CP</th><th>Ville</th><th>Détails</th></tr>';
for (var i = 0; i < data.length; i++) {
line = data[i];
html += '<tr>';
html += '<td>' + line.name + '</td>';
html += '<td>' + line.zip + '</td>';
html += '<td>' + line.city + '</td>';
html += '<td>';
html += '<a href="#" onclick="b2b.infos('+line.ref+', \'callback2\')">Voir</a>';
html += '</td></tr>';
}
html += '</table>';
$('#id_results').html(html);