IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AJAX Discussion :

[AJAX] Capter un paramètre envoyer par get en Ajax ?


Sujet :

AJAX

  1. #1
    Débutant Avatar de razily
    Inscrit en
    Février 2009
    Messages
    376
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 376
    Points : 154
    Points
    154
    Par défaut [AJAX] Capter un paramètre envoyer par get en Ajax ?
    Bonjour ;
    voilà j'utilise le frmaework codeigniter et je teste la possibilité de mettre Ajax avec ; ce framework est basé sur le modèle : MVC

    dans ma vue j'ai çà :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
     
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <title>Ajax essai</title>
         <script type = "text/javascript">
     
     function showUser(str)
     {
     var xmlhttp;
     if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      }  
     if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp = new XMLHttpRequest();
     }
     else
     {// code for IE6, IE5
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     xmlhttp.onreadystatechange = function()
     {
     if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
        }
     }
     //xmlhttp.open("GET", "ajaxcontrolleur.php?q="+str, true);
     xmlhttp.open("GET", "ajaxcontrolleur?q="+str, true);
     xmlhttp.send();
     }
     </script>
    </head>
    <body>
     
    <form>
    <select name="users" onchange="showUser(this.value)">
    <option value="">Select a person:</option>
    <option value="1">Peter Griffin</option>
    <option value="2">Lois Griffin</option>
    <option value="3">Glenn Quagmire</option>
    <option value="4">Joseph Swanson</option>
    </select>
    </form>
    <br />
    <div id="txtHint"><b>Person info will be listed here.</b></div>
     
    </body>
    </html>
    dans mon controlleur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
     
    <?php
    /**
     * @property CI_DB_active_record $db
     * @property CI_DB_forge $dbforge
     * @property CI_Benchmark $benchmark
     * @property CI_Calendar $calendar
     * @property CI_Cart $cart
     * @property CI_Config $config
     * @property CI_Controller $controller
     * @property CI_Email $email
     * @property CI_Encrypt $encrypt
     * @property CI_Exceptions $exceptions
     * @property CI_Form_validation $form_validation
     * @property CI_Ftp $ftp
     * @property CI_Hooks $hooks
     * @property CI_Image_lib $image_lib
     * @property CI_Input $input
     * @property CI_Language $language
     * @property CI_Loader $load
     * @property CI_Log $log
     * @property CI_Model $model
     * @property CI_Output $output
     * @property CI_Pagination $pagination
     * @property CI_Parser $parser
     * @property CI_Profiler $profiler
     * @property CI_Router $router
     * @property CI_Session $session
     * @property CI_Sha1 $sha1
     * @property CI_Table $table
     * @property CI_Trackback $trackback
     * @property CI_Typography $typography
     * @property CI_Unit_test $unit_test
     * @property CI_Upload $upload
     * @property CI_URI $uri
     * @property CI_User_agent $user_agent
     * @property CI_Validation $validation
     * @property CI_Xmlrpc $xmlrpc
     * @property CI_Xmlrpcs $xmlrpcs
     * @property CI_Zip $zip
     */
     
     
    class Ajaxcontrolleur extends CI_Controller 
    {
     
        public function __construct() 
        {
            parent::__construct();
        }
     
     
        public function index() 
        {
            
           //  echo 'je suis la ';
             /* on recupere la valeur du select */
           //  $q = $_GET["q"];
            
           $this->input->get('q');
            
            /* on le cherche dans la base */
            $data['infos'] = $this->modelajax->cherche($q);
            
            /* on charge vers la vue */
           $this->load->view('ajax_view',$data);
            
        //     var_dump($data); exit ;
            
        }
     
     
         
    }
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    ?>
    et dans mon modele

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
     
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <title>essai ajax</title>
    </head>
    <body>
     
             <table border="1">
                 <tr>
                     <th>id</th>
                     <th>titre</th>
                     <th>contenu</th>
                 </tr>
     
     
            <?php if ($infos!= null):
             foreach ($infos as $r):?>
     
                 <tr>
                     <td><?php echo $r['id']; ?></td>
                     <td><?php echo $r['titre']; ?></td>
                     <td><?php echo $r['contenu']; ?></td>
     
                 </tr>
     
     
     
     
     
     
     
     
        <?php endforeach;endif; ?>
     
                 </table>
     
     
     
     
     
     
     
     
     
     
     
    </body>
    </html>
    bien sur le problème vient sans doute de la récupération du paramètre via get
    j'ai essayé ces 2 codes mais çà ne marche pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
      //  $q = $_GET["q"];
     
           $this->input->get('q');
    est ce que quelqu'un a une idée ??

    merci

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Infographiste, webdevelopper, consultant en communication, bidouilleur sur Macintosh
    Inscrit en
    Septembre 2007
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Infographiste, webdevelopper, consultant en communication, bidouilleur sur Macintosh
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Septembre 2007
    Messages : 41
    Points : 35
    Points
    35
    Par défaut
    dans la ligne 33 de ta fonction showUser(str), je pense qu'il y a un problème de syntaxe.

    Tu as écrit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlhttp.open("GET", "ajaxcontrolleur?q="+str, true);
    A mon avis, il faudrait plutôt :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlhttp.open("GET", "ajaxcontrolleur.php?q="+str, true);

  3. #3
    Débutant Avatar de razily
    Inscrit en
    Février 2009
    Messages
    376
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 376
    Points : 154
    Points
    154
    Par défaut
    je te remercie de m'avoir répondu
    j'ai tout tenté mais il n'arrive pas à capter

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
       //  $q = $_GET["q"];
     
    //oueuivalent CI 
           $q = $this->input->get('q');
     
           echo $q ; exit ;

Discussions similaires

  1. [AJAX] Envoyer une valeur par get avec AJAX
    Par beegees dans le forum AJAX
    Réponses: 1
    Dernier message: 21/03/2009, 12h57
  2. Réponses: 7
    Dernier message: 13/01/2009, 17h11
  3. Réponses: 13
    Dernier message: 06/06/2007, 10h09
  4. Recuperer variable envoyer par get
    Par stephane92400 dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 13/03/2007, 13h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo