Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Problema chiamata AJAX

  1. #1

    Problema chiamata AJAX

    ho questa select nella pagina:
    codice:
            <tr>
                <td>Articolo:</td>
                <td>
                    <select name="articolo" onchange="changeDirImg(this.value);">
                        <option value="*">*</option>
                        <?php
                        foreach (selectArticolo() as $row) {
                            echo "<option value='" . $row['articolo_titolo'] . "'>" . $row['articolo_titolo'] . "</option>";
                        }
                        ?>
                    </select>
                </td>
            </tr>
    come si riempie nn penso abbia importanza....
    il problema è nella funzione changeDirImg che viene richiamata:
    codice:
    <script type="text/javascript">
                function changeDirImg(dir) {
                    alert('funzione = ok');
                    if (str == "*") {
                        document.getElementById("form_img").innerHTML = "";
                        return;
                    }
                    var xmlhttp;
                    var browser = navigator.appName;
                    if(browser == "Microsoft Internet Explorer"){
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } else {
                        xmlhttp = new XMLHttpRequest();
                    }
                        
                    xmlhttp.onreadystatechange = function() {
                        alert('evento = ok');
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                            document.getElementById("form_img").innerHTML = "";
                        }
                    }        
                    xmlhttp.open("GET","art-img.php?art_id=" + dir, true);
                    xmlhttp.send();
                }
            </script>
    ho messo due alert.
    il primo viene visualizzato e quindi entra nella funzione.
    il secondo no.
    eppure mi sembra tutto giusto.

  2. #2
    ho quasi sistemato.
    allora nella pagina art_gallery.php c'è il form:
    codice:
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" id="form_img" name="modulo" onsubmit="return deleteImages();">
        <table>   
            <tr>
                <td>
                    Seleziona tutto
                </td>
                <td>
                    <input type="submit" value="Elimina" name="elimina_img" />
                </td>
            </tr>
            <tr>
                <td>Articolo:</td>
                <td>
                    <select name="articolo" onchange="changeDirImg(this.value);">
                        <option value="*">*</option>
                        <?php
                        foreach (selectArticolo() as $row) {
                            echo "<option value='" . $row['articolo_titolo'] . "'>" . $row['articolo_titolo'] . "</option>";
                        }
                        ?>
                    </select>
                </td>
            </tr>
            <?php
            $art_id = $_GET['art_id'];
            $dirname = "../img_articoli/" . $art_id . "/";    
            foreach (showImg($_GET['art_id']) as $file) {
                echo '<tr><td><input type="checkbox" name="check[]" value="' . $file['galleria_art_nome'] . '" /></td>';
                echo '<td>[img]' . $dirname . $file['galleria_art_nome'] . '[/img]</td>';
                echo '<td>' . $file['galleria_art_didascalia'] . '</td></tr>';
            }
            ?>
        </table>
    </form>
    la funzione JS è questa:
    codice:
            <script type="text/javascript">
                function changeDirImg(dir) {
                    var td_img = "form_img";
                    if (dir == "*") {
                        document.getElementById(td_img).innerHTML = "";
                        return;
                    }
                    var xmlhttp;
                    var browser = navigator.appName;
                    if(browser == "Microsoft Internet Explorer"){
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } else {
                        xmlhttp = new XMLHttpRequest();
                    }
                        
                    xmlhttp.onreadystatechange = function() {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                            document.getElementById(td_img).innerHTML = xmlhttp.responseText;
                        }
                    }        
                    xmlhttp.open("GET","art_gallery.php?art_id=" + dir, true);
                    xmlhttp.send();
                }
            </script>
    il problema è che oltre alle imagini mi duplica anche il resto della pagina (menu e altri form).
    perchè??

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.