Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2012
    Messaggi
    52

    Invio dati jquery ajax a file php

    Salve volevo sapere come si ricevere una variabile tramite ajax con il metodo post che nome viene attribuito al $_POST['qui che si mette io ho messo la chiave che si trova nel parametro data di ajax']?
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script>
    </head>
    
    <body>
    <textarea width="200" height="300" id="commentoid" name="commento">
    </textarea>
    <button id="tastocommento">invia</button>
    <div id="visualizza"></div>
    <script type="text/javascript">
    var commento = $("#commentoid").val();
    $('button#tastocommento').click(function(){	
    $.ajax({
    url:"commento.php",
    type: "post",
    data: 'commento=' + commento,
    success:function(cacca){
    $('#visualizza').html(cacca);
    }
    });
    });
    </script>
    <iframe src="commento.php" width="400px;height="400px;>
    </iframe>
    </body>
    </html>
    il file commento.php
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    </head>
    
    <body>
    ciaooooooooo
    <?php
    $commento=$_POST['commento'];//qui ricevo beneeeeeeeeeeeeeeeeeeeeeee?
    echo $commento;
     ?>
    </body>
    </html>

  2. #2
    Utente di HTML.it L'avatar di m4rko80
    Registrato dal
    Aug 2008
    residenza
    Milano
    Messaggi
    2,655
    Ciao, prima di tutto includi se non error due volte jquery(da correggere).
    Lo script commento.php non ritorno solo $_POST['commento'] ma anche tutto l'HTML di quello script perchè lo generi con l'html.

    Lo script principale dovrebbe avere anche un ready di jQuery tipo
    codice:
    <script type="text/javascript">
    $(function(){
    var commento = $("#commentoid").val();
    $('button#tastocommento').click(function(){	
    $.ajax({
    url:"commento.php",
    type: "post",
    data: 'commento=' + commento,
    success:function(cacca){
    $('#visualizza').html(cacca);
    }
    });
    });
    });
    </script>
    Il metodo ajax post ha altre funzioni da usare per vedere se va a buon fine o meno.
    Se guardi per esempio:
    codice:
    $.ajax( "example.php" )
    .done(function() {
    alert( "success" );
    })
    .fail(function() {
    alert( "error" );
    })
    .always(function() {
    alert( "complete" );
    });
    QUI

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.