Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Jquery php passaggio valori

    Tramite la funzione ajax di Jquery vorrei passare un valore ad un file php
    file php
    Codice PHP:
    <?php

    $id 
    $_POST['id'];
    if (
    $id==1) echo 'Chiamata numero 1';
    if (
    $id==2) echo 'Chiamata numero 2';
    if (
    $id==3) echo 'Chiamata numero 3';

    if (
    $id!=&& $id!=&& $id!=3) echo $id;

    ?>
    file js
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>File corso</title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
      <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery('span.delete').click(function()
            {
                var id = jQuery(this).attr('id')
                $.ajax({
                    type: 'POST',
                    url: 'test.php',
                    data: id,
                    success: function(response){
                        jQuery('<div></div>').addClass('output').insertAfter('table.file');
                        jQuery('.output').html(response);
                    }
                });
                alert (id);
            });

        });
      </script>
    </head>
    <body>
    <?php require_once 'Cartella.php' ?>
    <?php 
    if (count($conenuto)>0)
    {
    ?>
    <table class="file">
                <tr>
                <th>NOME FILES</th>
                <th>DIMENSIONI</th>
                <th>AZIONI</th>
                </tr>
                <tr>
    <?php    
        
    foreach($conenuto as $valore)
        {
            echo 
    '<td><a href=\''.$percorso_corso.'/'.$valore.'\'>'.$valore.'</a></td>
                  <td>-</td>'
    ;
            echo  
    '<td><span class="delete" id="'.$percorso_corso.'/'.$valore.'">X</span></td>
                  </tr>'
    ;
        }
    }
    else
        echo 
    '<h1>La cartella [i]'.substr($percorso_corso$car_dir_prin).' [/i]è vuota</h1>';
    ?>
    </tr></table>
    </body>
    </html>
    Il valore che li vorrei passare è id dello span, ma non va mi dice
    Notice: Undefined index: id in.....

  2. #2
    Errore era nel valore data
    corretto in data: 'id='+id,

    Adesso però i valori restituiti dal div con id output sono tutti uguali cioè

    Se il div è
    1
    1
    1

    quando li passo id 2 tutto diventa
    2
    2
    2

    invece io vorrei che si vada ad aggiungere e non sostituire.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.