0
當用戶提交表單時,我正在使用隱藏的輸入向Ajax發送一些額外的值。我使用隱藏值的原因是因爲我可以爲每個文本字段分配一個按鈕,併爲其指定一個文本框。每按一下按鈕,我必須發送文本字段中的值加上一些額外的值。使用隱藏輸入通過Ajax發送額外數據
問題是,任何人都可以檢查Chrome中的代碼(例如)並更改隱藏字段中的值。有沒有更好的方法來做到這一點?
編輯:添加一些代碼,以更好地說明我的問題
HTML
<div>
<input type="textfield" name="value1" value="Default value for textfield" />
<input type="hidden" class="hiddenValue" name="hiddenSuperSecretValue" value="superSecret" />
<button class="submitButton">Submit</button>
<input type="textfield" name="value2" value="Default value for textfield" />
<input type="hidden" class="hiddenValue" name="hiddenSuperSecretValue" value="superSecret" />
<button class="submitButton">Submit</button>
... more fields ...
</div>
JS
$('.submitButton').click(function(){
dataVar = "someValue" = $(this).closest('.hiddenValue').val();
$.ajax({
type: "POST",
url: "/submitAjaxStuff.php",
data: dataVar,
cache: false,
success: function(response){
doSomething(response);
}
});
});
由於每個字段的值不同,我不想爲每個字段使用ajax函數,所以我不知道如何使用session。查看我對原始帖子的編輯。 – 2013-04-12 14:19:32