Greetings to everyone in this community I am developing a project that generates a shopping list, this list is made in a table and the product code and quantities are stored in an array containing the 2 array, then the sent by POST through ajax with a json. up there all right until you return a message in the "success" function
var productos=new Array();
var cantidades=new Array();
var combinado= new Array(2);
combinado[0]=productos;
combinado[1]=cantidades;
var jsonString = JSON.stringify(combinado);
$.ajax({
type: "POST",
url: "ingrcomp2.php",
data: {data : jsonString},
cache: false,
success: function(){
alert("OK");
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
This is the server code (ingrcomp2.php):
$array = json_decode($_POST['data']);
$fecha_compra=date("Y-m-d");
$hora=new DateTime();
$hora->setTimezone(new DateTimeZone('America/Bogota'));
$hora=$hora->format('H:i:s');
$usuario=$_REQUEST['sel_usuario'];
$conexion=mysqli_connect("localhost","root","","sima") or die("Problemas en la conexion a la Base de Datos SIMA");
for($i=0;$i<count($array);$i++) {
$compra=$array[1][i];
$producto=$array[0][i];
After this, several queries are made based on the purchase and product. Am I traversing the array? Am I assigning badly? Am I using ajax correctly? Thanks for your time