-3
回到我從PHP返回JSON編碼數據阿賈克斯成功的功能,這裏是代碼廣東話訪問JSON編碼數據從PHP
<?php
if ($run) {
$response=array();
$response['email']=$email;
$response['name']=$name;
echo json_encode($response);
exit();
}
?>
我想通過AJAX成功函數來訪問這些數據,這就是我試圖
<script type="text/javascript">
$("#contact-form").submit(function(e){
e.preventDefault();
if (check()) {
$.ajax({
url: 'reguser.php',
async: true,
cache: false,
data: $('#contact-form').serialize(),
type:'post',
success: function (result) {
var json = result;
obj = JSON.parse(json);
alert(obj.email);
}
});
}
});
</script>
如何檢索電子郵件和姓名,我在後端PHP呼應..
什麼是錯誤?並請分享完整的ajax請求 – Naincy
我無法訪問的數據,它顯示undefined – gANDALF
**什麼**顯示'undefined'? 'obj'或'obj.email'?或'結果'?或'$'?或者是其他東西? – Quentin