AJAX - problema al enviar variable por ajax (imagen y el id al actualizar)

 
Vista:
Imágen de perfil de Ricardo
Val: 2
Ha aumentado su posición en 4 puestos en AJAX (en relación al último mes)
Gráfica de AJAX

problema al enviar variable por ajax (imagen y el id al actualizar)

Publicado por Ricardo (2 intervenciones) el 17/09/2020 17:56:13
buenas a todos espero que me ayuden con este problema intento actualizar una imagen desde mi ventana modal pero al enviar por ajax no recibe el ID del producto espero que me ayuden adjunto codigo:

---------------------MODAL------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
<div class="col-md-5 h-100" align="center">
    <div id="load_img">
        <img class="img-responsive" src="<?php echo $row['imagen'];?>" alt="Logo">
    </div>
    <br>
        <div class="row">
            <div class="col-md-6" >
                <div class="form-group">
                    <input class='filestyle' data-buttonText="Logo" type="file" name="imagefile" id="imagefile" onchange="upload_image('<?php echo  $row['id_producto'];?>');">
                </div>
            </div>
        </div>
</div>

----------------------------------ajax-----------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function upload_image(id){
    var inputFileImage = document.getElementById("imagefile");
    var file = inputFileImage.files[0];
 
    if( (typeof file === "object") && (file !== null) )
    {
        $("#load_img").text('Cargando...');
        var data = new FormData();
        data.append('imagefile',file);
 
        $.ajax({
            url: "ajax/update_img.php",
            type: "POST",
            data:"id="+id, data,
            contentType: false,
            cache: false,
            processData:false,
            success: function(data)
            {
                $("#load_img").html(data);
            }
        });
    }
}

--------------------- recibe los datos del ajax -----------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (isset($_FILES["imagefile"])){
 
    $id_p=$_POST["id"];
 
    $target_dir="../vendor/img/products/";
    $image_name = time()."_".basename($_FILES["imagefile"]["name"]);
    $target_file = $target_dir . $image_name;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    $imageFileZise=$_FILES["imagefile"]["size"];
/* Fin Validacion*/
    if ($imageFileZise>0){
        move_uploaded_file($_FILES["imagefile"]["tmp_name"], $target_file);
        $logo_update="imagen='vendor/img/products/$image_name' ";
 
    }	else { $logo_update="";}
        $sql = "UPDATE products SET $logo_update WHERE id_producto='".$id_p."' ";
        $query_new_insert = mysqli_query($con,$sql);

PSDT: la imagen si se almacena en la carpeta pero no hace el update en la bd por que noreconoce ID


cap
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder