Visualizzazione dei risultati da 1 a 10 su 24

Discussione: MVC e ajax

Hybrid View

  1. #1
    si ma come lo crei il selection?
    deve avere una struttura tipo questa:
    codice:
    var data = { 
        "nome": "NOME", 
        "cognome": "COGNOME", 
        "eta": 20  
    }; 
     
    $.getJSON(URL, data, function (result) { 
        ...... 
    });

  2. #2
    Utente di HTML.it L'avatar di leaf
    Registrato dal
    Oct 2012
    Messaggi
    316
    Quote Originariamente inviata da fermat Visualizza il messaggio
    si ma come lo crei il selection?
    deve avere una struttura tipo questa:
    codice:
    var data = { 
        "nome": "NOME", 
        "cognome": "COGNOME", 
        "eta": 20  
    }; 
     
    $.getJSON(URL, data, function (result) { 
        ...... 
    });
    nel primo post c'è il codice completo. lo riporto qui. la select funziona correttamente

    codice:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Load Cars By Choice</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
        $(document).ready(function (){
            $('#select').change(function (){
    
                    //debug
                    var model = $(this).val();
    
                    var str = "";
    
                    $("select option:selected").each(function(){
                        str += "<br/><div><b>Company Name: </b>" + $(this).text() + "</div><br/>";
    
                        var selection = $(this).text();
    
                        var carModelUrl = ".../my_mvc/index.php/loadCarsByChoice";
    
                        $.getJSON(carModelUrl, selection, function(json){
                            console.log("JSON: ", json);
                            str += "<table>";
    
                            for (var i = 0; i < json.length; i++) {
                                str += "<tr><td>" + (i+1) + " - " + json[i].BrandName +
                                "</td><td>" + json[i].Model +
                                "</td><td>" + json[i].Colour +
                                "</td><td><img src='../assets/" + json[i].BrandName + ".jpg'></img></td></tr>";
                            }
    
                            str += "</table>";
    
                            document.getElementById("placeholder").innerHTML=str;
    
                        });
                    });
                });
    })
    </script>
    </head>
    <body>
        <h1>Choose a car to see details</h1>
        <form>
            <select id="select">
                <?php
                for ($i=0; $i < count($data); $i++) { 
                    echo "<option value='".$data[$i]."'>".$data[$i]."</option>";
                }
                ?>
            </select>
        </form>
    
        <div id="placeholder"></div>
    </body>
    </html>

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 © 2026 vBulletin Solutions, Inc. All rights reserved.