我在将 ajax 响应的结果放入 html 元素时遇到问题。这是我的 php 将东西插入数据库,插入部分工作但无法将结果放入 div。
include('konekcija.php');
if ($_POST['form_submitted'] = 1) {
$aktKod = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
$sifra = $_POST['password'];
$korIme = $_POST['username'];
$email = $_POST['email'];
$upit = "INSERT INTO korisnici(Username,Password,Email,Status,AktivacioniBroj,Uloga)
VALUES ('$korIme','$sifra','$email','verify',$aktKod,'user') ";
if(mysql_query($upit)) { $return['success'] = "Uspesna registracija"; }
else { $return['error'] = "neuspesna registracija"; }
echo json_encode($return);
mysql_close($conn); }
jQuery代码:
$(document).ready(function() {
$('#prijava').click(function() {
$.ajax({
url: "registracija.php",
type: "POST",
dataType:"json",
data: {form_submitted:1, username: $('#user').val(), password: $('#pass').val(), email: $('#email').val()},
succes: function(data) { $('#errorCol').html(data.success); }
}); }); });
还有我在html中的表格:
<form method="POST" name="register" action="" onsubmit="return false">
<table id="register">
<tr>
<td style="padding-bottom:30px; padding-right:20px;"><span style=" font-size:14px; color:#666;">Korisnicko Ime:</span></td>
<td><input id="user" type="text" name="username" /></td>
</tr>
<tr>
<td style="padding-bottom:30px; padding-right:20px;"><span style=" font-size:14px; color:#666;">Sifra:</span></td>
<td> <input id="pass" type="password" name="password" /></td>
</tr>
<tr>
<td style="padding-bottom:30px; padding-right:20px;"><span style=" font-size:14px; color:#666;">Ponovite Sifru:</span></td>
<td> <input id="pass2" type="password" name="password" /></td>
</tr>
<tr>
<td style="padding-bottom:30px;"><span style=" font-size:14px; color:#666;">Email:</span></td>
<td><input id="email" type="text" name="email" /> <input type="hidden" name="form_submitted" value="1"/></td>
</tr>
<tr>
<td style="padding-bottom:30px;" colspan="2" align="center"><input id="prijava" type="submit" value="Prijavi" /></td>
</tr>
<tr>
<td id="errorCol" colspan="2" align="center"></td>
</tr>
</table>
</form>
所以它将数据插入数据库,但是我需要将响应显示到 id 为“errorCol”的元素中的部分不起作用,它只是保持为空。试图返回 json 数组。