这段代码对我不起作用!我想在使用UIkit的通知中显示变量$ nom。 这里是php文件(verif1.php):
<?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
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO client ( nom_client,IMEI,numero ) VALUES ('$nom',$IMEI,$numero)";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully pour "."$nom";
echo json_encode(array('nom' => $nom ));
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
` 以及这里的javascript代码:
<script language="Javascript">
$.ajax({
url: 'verif1.php',
type: 'POST',
dataType: 'json',
data: {
"varA": nom
},
cache: false,
success: function(data) {
alert('Items added');
},
error: function(e) {
console.log(e.message);
}
});
</script>
<script language="Javascript">
$(document).ready(function() {
setTimeout(function() {
ui.notify('Notification 01', 'Cette premiere notification s\'affichera quelques secondes puis disparaitra.')
.effect('slide');
setTimeout(function() {
ui.notify('Notification 02', 'Cette deuxieme notification s\'affichera plus longtemps que la premiere.')
.closable()
.hide(8000)
.effect('slide');
}, 200);
}, 200);
});
</script>
问题是$ .ajax功能没有显示任何内容,我不知道如何知道它是否正常工作! 请帮助:)
答案 0 :(得分:0)
第一件事:
将所有$ _GET替换为$ _POST
因为您在post
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'];
另外,根据您提供的代码:
data: {"varA": nom},
nom
定义在哪里?
答案 1 :(得分:0)
我有一张表格
<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 />
<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" />
</form>
</div>
从这个表格我直接去verif1.php所以idon真的知道怎么擦除那些$ _GET