我有一個jQuery自動完成功能,由json_encoded PHP數組提供。一切正常,但當我右鍵點擊該網站查看頁面源時,我可以看到整個數組。這個數組包含哪些敏感信息?有沒有更好的方法來組織這些代碼,使它在相同級別的功能上更私密?有沒有辦法從HTML源代碼隱藏自動完成數組?
在主PHP/HTML頁面:
<?php include 'autocomplete.php'; ?>
,其中包括:
<?php
// connect to db
//fetch first and last name
$sql="SELECT first, last FROM names";
$result = mysqli_query($web_dbi, $sql) or die("Error " . mysqli_error($web_dbi));
while ($f=mysqli_fetch_array($result)) {
$names[] = array(
'label' => $f['first'] . " " . $f['last'];
);
}
echo json_encode($names);
?>
背面的主PHP/HTML頁面上,我有一些JQuery的:
... (JQuery CDNs)
<script type="text/javascript">
$(function() {
$("#inputfield").autocomplete({
source: "autocomplete.php",
minLength: 1,
select: function(event, ui) {
log(ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value);
}
});
});
</script>
的主要問題是,在HTML頁面的源代碼中,這是可見的:
$(function() {
var autocompletevalues = ["name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name","name"];
$("#inputfield").autocomplete({
dataType: "json",
source: availableTags
});
});
自動完成值是通過AJAX動態牽強,你沒有將其存儲在一個變量。 –
是的,我做到了。如果正確實施,您的HTML頁面源不應該以這種方式顯示自動完成值。 –
所以你推薦我用ajax實現自動完成嗎? – draft