Better error management

This commit is contained in:
Laurent Destailleur 2014-08-31 15:09:10 +02:00
parent 154d1520fb
commit 6e54577167
2 changed files with 25 additions and 21 deletions

View File

@ -98,26 +98,30 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
$("input#search_'.$htmlname.'").autocomplete({
source: function( request, response ) {
$.get("'.$url.($urloption?'?'.$urloption:'').'", { '.$htmlname.': request.term }, function(data){
response($.map( data, function( item ) {
if (autoselect == 1 && data.length == 1) {
$("#search_'.$htmlname.'").val(item.value);
$("#'.$htmlname.'").val(item.key).trigger("change");
}
var label = item.label.toString();
var update = {};
if (options.update) {
$.each(options.update, function(key, value) {
update[key] = item[value];
});
}
var textarea = {};
if (options.update_textarea) {
$.each(options.update_textarea, function(key, value) {
textarea[key] = item[value];
});
}
return { label: label, value: item.value, id: item.key, update: update, textarea: textarea, disabled: item.disabled }
}));
if (data != null)
{
response($.map( data, function(item) {
if (autoselect == 1 && data.length == 1) {
$("#search_'.$htmlname.'").val(item.value);
$("#'.$htmlname.'").val(item.key).trigger("change");
}
var label = item.label.toString();
var update = {};
if (options.update) {
$.each(options.update, function(key, value) {
update[key] = item[value];
});
}
var textarea = {};
if (options.update_textarea) {
$.each(options.update_textarea, function(key, value) {
textarea[key] = item[value];
});
}
return { label: label, value: item.value, id: item.key, update: update, textarea: textarea, disabled: item.disabled }
}));
}
else console.error("Error: Ajax url '.$url.($urloption?'?'.$urloption:'').' has returned an empty page. Should be an empty json array.");
}, "json");
},
dataType: "json",

View File

@ -18,7 +18,7 @@
*/
/**
* \file htdocs/product/ajax/products.php
* \file htdocs/product/ajax/company.php
* \brief File to return Ajax response on product list request
*/