Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di fostex
    Registrato dal
    Mar 2000
    Messaggi
    136

    valori sballati con ajax ie8

    Ciao,

    con questo script appaiono dei quadrotti con scritto dentro i valori di:
    id, name, qty e 2 bottoni (+ e -)
    vorrei che cliccando i bottoni + e - mi aumenti/diminuisca di uno il valore di "qty".
    Cosa che in effetti funziona perfettamente su Firefox, Chrome, Safari sia su win che osx...
    ma su ie8 (testato su 3 pc, uno vista32 e l'altro vista64) cambia anche i valori di "qty" (apparentemente con numeri a caso) di altri quadrotti.
    In realtà il db viene aggiornato giusto (facendo refresh tornano i valori gusti) ma a video no.

    Qualcuno sa dirmi il motivo!!!!



    Ciao e grazie!

    Codice PHP:
    <html>
    <body>
    <script language="javascript" type="text/javascript">
    <!--
    //Browser Support Code
    function ajaxFunction( Bool, Checker){
    var ajaxRequest = null; // The variable that makes Ajax possible!
        try{
        // Opera 8.0+, Firefox, Safari
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            // Internet Explorer Browsers
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    // Something went wrong
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4 ){
                var ajaxDisplay = document.getElementById("ajaxDiv");
                //var ajaxDisplay = document.getElementById("fig_<?php echo $row[id]; ?>");
                
                ajaxDisplay.innerHTML = ajaxRequest.responseText;
            }
        }

        //var done_qty = document.getElementById("done_qty").value;
        var queryString = "?bool_id=" + Bool + "&done_qty=" + Checker;

        ajaxRequest.open("GET", "combo2.php" + queryString, true);
        ajaxRequest.send(null);

    //alert(Bool);
    }

    //-->
    </script>

    <div id="ajaxDiv">
    <?php
    $dbhost 
    "xxxxxxxxxxxx";
    $dbuser "xxxxxxxxxxx";
    $dbpass "xxxxxxxxx";
    $dbname "xxxxxxxx";
        
    //Connect to MySQL Server
    mysql_connect($dbhost$dbuser$dbpass);
            
    //Select Database
    mysql_select_db($dbname) or die(mysql_error());
            
    // Retrieve data from Query String
    $done_qty $_GET['done_qty'];
    $bool_id $_GET['bool_id'];
            
    // Escape User Input to help prevent SQL Injection
    $done_qty mysql_real_escape_string($done_qty);
    $bool_id mysql_real_escape_string($bool_id);

            
    //build query
    //$done_qty1 = $done_qty;
    if($bool_id){
        
        echo 
    "bool_id!: $bool_id\n";
        echo 
    "done_qty!: $done_qty\n";
        
    $query "UPDATE ajax_example SET  qty = '$done_qty' WHERE id = '$bool_id'";
        
    $qry_result1 mysql_query($query) or die(mysql_error());
            }
            
    //Execute query
    $query "SELECT * FROM ajax_example ORDER by id ASC";
    $qry_result mysql_query($query) or die(mysql_error());

            
    //Build Result String

            // Insert a new row in the table for each person returned
    while($row mysql_fetch_array($qry_result)){
        
        
    ?>
        <div  id="fig_<?php echo $row[id]; ?>"class="fig">
    <?php    
            
    echo "ID: $row[id]
    "
    ;
            echo 
    "Name: $row[ae_name]
    "
    ;
            echo 
    "qty: $row[qty]
    "
    ;
            
    ?>
            <td><input type="button" onClick="ajaxFunction('<?php echo $row[id]."','".($row[qty]+1); ?>')"  value="+" /></td>
            <td><input type="button" onClick="ajaxFunction('<?php echo $row[id]."','".($row[qty]-1); ?>')" value="-" /></td>

        </div>
        <?php
    }
    ?>
    </div>

    </body>
    </html>

  2. #2
    Utente di HTML.it L'avatar di fostex
    Registrato dal
    Mar 2000
    Messaggi
    136
    cambiando:
    ajaxRequest.open("GET", "combo2.php" + queryString, true);
    in
    ajaxRequest.open("POST", "combo2.php" + queryString, true);
    sembra funzionare anche su ie.

    Ma è corretto? cioè ci sono controindicazioni che orora mi sfuggono?


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.