beginner in ajax: does not make the respective queries in server

0

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

    
asked by Homero Metalero 01.12.2016 в 14:18
source

1 answer

0

You say that a message comes out in the success function. But I do not see you doing anything with the returned values of the call AJAX . In the success function you must add the parameter that will wrap the server's response.

$.ajax({
    type: "POST",
    url: "ingrcomp2.php",
    data: {data : jsonString}, 
    cache: false,
    success: function(respuesta){
        console.log(respuesta);
    },
    error: function(xhr, status, error) {
        var err = eval("(" + xhr.responseText + ")");
        alert(err.Message);
    }       
});
    
answered by 01.12.2016 / 14:30
source