所以在這個腳本中變量「encrypted
」應該通過ajax發送並傳遞到upload.php
,但我無法做到這一點。比方說,在阿賈克斯我用一個不同的變量替換「encrypted
」變量,它的工作原理。爲什麼不能通過ajax發送變量「encrypted
」到upload.php
?雖然AJAX不能發送Javascript變量
<script src="http://cryptojs.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
$(document).ready(function() {
// variables to be sent to php
var formData = {
'encrypted_data': encrypted
};
// process the form
$.ajax({
type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
url: 'upload.php', // the url where we want to POST
data: formData, // our data object
dataType: 'json', // what type of data do we expect back from the server
encode: true
})
// using the done promise callback
.done(function(data) {
// log data to the console so we can see
console.log(data);
// here we will handle errors and validation messages
});
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
});
</script>
將您的腳本引用移至aes.js,以便使用您自己的代碼在腳本塊上方。 – Chev
嘗試過,沒有工作 – AgentPigman
在控制檯中獲取任何錯誤? – Chev