2015-07-27 11:10
浏览 75

使用ajax / jquery从php获取变量

this code doesn't work for me ! i want to display the variable $nom in a notification using UIkit . here the php file (verif1.php) :


$IMEI = $_GET['IMEI'];
$region = $_GET['region'];
$numero = $_GET['numero'];
$nom = $_GET['nom_client'];

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

/* <input type="hidden" id="nom" value="valeurDeMariable"> </input> */

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $sql = "INSERT INTO client ( nom_client,IMEI,numero ) VALUES ('$nom',$IMEI,$numero)";
    // use exec() because no results are returned
    echo "New record created successfully pour "."$nom";
    echo json_encode(array('nom' => $nom ));
catch(PDOException $e)
    echo $sql . "<br>" . $e->getMessage();

$conn = null;


` AND HERE's the javascript code :

<script language="Javascript">
    url: 'verif1.php',
    type: 'POST',

    dataType: 'json',
    data: {
        "varA": nom

    cache: false,
    success: function(data) {
        alert('Items added');
    error: function(e) {
<script language="Javascript">
$(document).ready(function() {

    setTimeout(function() {
        ui.notify('Notification 01', 'Cette premiere notification s\'affichera quelques secondes puis disparaitra.')

        setTimeout(function() {
            ui.notify('Notification 02', 'Cette deuxieme notification s\'affichera plus longtemps que la premiere.')

        }, 200);
    }, 200);


the problem is that $.ajax function doesn't show anything and i don't know how to know if it's working or not!! please help :)

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongtang6681 2015-07-27 11:20

    First thing:

    Replace all $_GET with $_POST

    Because, you have chose post method in: type: 'POST',

    $IMEI = $_GET['IMEI'];
    $region = $_GET['region'];
    $numero = $_GET['numero'];
    $nom = $_GET['nom_client'];


    $IMEI = $_POST['IMEI'];
    $region = $_POST['region'];
    $numero = $_POST['numero'];
    $nom = $_POST['nom_client'];

    Also, from the code you have provided:

    data: {"varA": nom},

    Where is nom defined?

    解决 无用
    打赏 举报
  • douhe4608 2015-07-27 11:28

    i have a form

    <div id="content">
                <form method="get" action="verif1.php">
                    <b><label for="IMEI">Veuillez entrer votre IMEI : </label></b>
                    <input type="string" id="IMEI" name="IMEI"/><br /><br />
                    &nbsp;&nbsp;<b><label for="nom_client">Veuillez entrer votre nom : </label></b>
                    <input type="string" id="nom_client" name="nom_client"   /><br /><br />
                    <b><label for="region">Veuillez entrer votre région : </label></b>
                    <input type="string" id="region" name="region"   /><br /><br />
                    <b><label for="numero">Veuillez entrer votre numéro : </label></b>
                    <input type="string" id="numero" name="numero"   /><br /><br />
                    <input type="submit" value="Enter" />

    and from this form i go directly to verif1.php so idon't really know how to erase those $_GET

    解决 无用
    打赏 举报

相关推荐 更多相似问题