Hi, I can’t solve this problem.
I have two app.request requests.
The former works fine on iOS and Android, but the latter only works on Android.
Explanation: the first app.request generates a virtual list with elements, these elements are the ones that call, through a function, the second app.request.
First request
app.request({
url: 'http://xxx.xx.xx.xx/webapps/get_producto.php?NOM_LARGO=' + busquedaUpper,
method: 'POST',
dataType: 'XML',
crossDomain: true,
success: function (data, textStatus) {
var doc = $$(new DOMParser().parseFromString(data, 'text/html'));
doc.find('producto').forEach(function (itm) {
// ... here generates the list ...
});
var virtualList = app.virtualList.create({
// List Element
el: '.virtual-list-busqueda',
cache: false,
// Pass array with items
items: lista_medicamentos,
emptyTemplate: 'No se encontraron resultados.',
// List item Template7 template
itemTemplate: '<li class="btn-sucursales" id="medicamento{{codigo}}" data-codigo="{{codigo}}">' +
'<a href="#" onClick="sucursalFunction(this)" class="item-link item-content no-padding-left" data-codigo="{{codigo}}" data-nombre="{{nombre}}" id="{{nombre}}">' +
'<div class="item-inner padding-left padding-right-half">' +
'<div class="item-title">' +
'<span class="busqueda-resultados-titulo"><b>{{nombre}}</b></span>' +
'<div class="item-footer">Ver sucursales</div>' +
'</div>' +
'<div class="item-after"><i class="material-icons rotar-0">add</i></div>' +
'</div>' +
'</a>' +
'</li>',
});
app.preloader.hideIn('.preloader-div');
},
This onClick calls the second request onClick="sucursalFunction(this)"
Second request (same url of the first request)
function sucursalFunction(data) {
var codigo = $$(data).attr('data-codigo');
var nombre = $$(data).attr('data-nombre');
var lista_sucursales = [];
app.request({
url: 'http://1xx.1xx.xxx.xxx/webapps/get_stock.php?cod_alfabeta=' + codigo,
method: 'POST',
dataType: 'XML',
crossDomain: true,
beforeSend: function() {
console.log('http://xxx.1xx.2xx.1xx/webapps/get_stock.php?cod_alfabeta=' + codigo);
},
success: function (dataProducto) {
var docsuc = $$(new DOMParser().parseFromString(dataProducto, 'text/html'));
docsuc.find('sucursal').forEach(function (itmsuc) {
// averiguo si hay stock
var stock_suc = $$(itmsuc).find('can_stk').text();
// si tiene stock lo inserto en la variable
if (stock_suc > 0) {
var nombre_suc = $$(itmsuc).find('nom_sucursal').text();
var localidad_suc = $$(itmsuc).find('des_localidad').text();
var telefono_suc = $$(itmsuc).find('des_tel').text();
var direccion_suc = $$(itmsuc).find('des_direccion').text();
var suc = {};
suc.sucursal = nombre_suc;
suc.localidad = localidad_suc;
suc.telefono = telefono_suc;
suc.direccion = direccion_suc;
suc.stock = stock_suc;
lista_sucursales.push(suc);
}
});
// Comparar localidades y ordenar
function compare(a, b) {
// Use toUpperCase() to ignore character casing
const localidadA = a.localidad.toUpperCase();
const localidadB = b.localidad.toUpperCase();
let comparison = 0;
if (localidadA > localidadB) {
comparison = 1;
} else if (localidadA < localidadB) {
comparison = -1;
}
return comparison;
}
// Fin comparar localidades
lista_sucursales.sort(compare);
var popupTemplate = Template7.compile(
'<div class="popup sucursales-popup">' +
'<div class="view">' +
'<div class="page bg-color-white">' +
'<div class="navbar bg-color-white">' +
'<div class=""></div>' +
// ... here generates the list ...
'</div>' +
' </div>',
);
app.popup.create({
swipeToClose: true,
content: popupTemplate({
lista_sucursales
})
}).open();
},
error: function (xhr, textStatus, errorThrown) {
var msg = '';
if (xhr.status == 0) {
msg = 'Not connect.\n Verify Network.';
} else if (xhr.status == 404) {
msg = 'Requested page not found. [404]';
} else if (xhr.status == 500) {
msg = 'Internal Server Error [500].';
} else if (textStatus === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (textStatus === 'timeout') {
msg = 'Time out error.';
} else if (textStatus === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + xhr.responseText;
}
console.log(msg);
console.log(errorThrown);
},
});
};
The data arrives ok to the second request, because in the beforeSend the console.log shows me the url with the parameter correctly.
The error it gives me is not that I do not have an internet connection, but that is not the case.
I am using framework7 v.6 version
I can’t determine why it doesn’t work on iOS, on Android it works perfectly. The function is called and with the correct parameters, since beforeSend shows me on the console that it is so.
Thanks in advance.
I’m stuck with this.