即時通訊使用js將變量分配給隱藏表單的值。當我嘗試在PHP中訪問它時,沒有任何顯示。我知道JavaScript是正確的添加到窗體的值,但形成一些原因PHP只是不會得到它。繼承人的代碼:隱藏表單不會將變量傳遞給php
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="textualizer.min.js"></script>
</head>
<style type="text/css">
#txtlzr{color:#585856; font-size:50px; width:1200px; height:100px;
margin-left:10%;
margin-top:80px;
font-family:"futura";
position: fixed;
}
</style>
<body>
<div id="txtlzr"></div>
<form name="kwoteForm" action="main.php" method="post"/>
<input type="hidden" id="kwoteString" name="kwoteString" value="bob" />
<input class="kwote" type="text" maxlength="40" id="kwote"placeholder="Enter a something here."/>
<input class="name" type="text" maxlength="17" id="name" placeholder="Enter your name."/>
<input class="post" type="submit" value="Add comment" onclick="add_comment();" />
</form>
<script language="javascript">
var COMMENTS_FOR_DISPLAY = new Array('OOOOOOO ITS WORKING : NICK');
// Adds a new comment, name pair to the Array feeding textualizer.
function add_comment() {
// Retrieve values and add them to Array.
var new_comment = $('#kwote').val();
var new_name = $('#name').val();
COMMENTS_FOR_DISPLAY.push(new_comment + ': ' + new_name);
// Reset <input> fields.
$('#kwote').val('');
$('#name').val('');
//Take comment array and put it into a string.
var arrayAsString = JSON.stringify(COMMENTS_FOR_DISPLAY);
//Assign value of the string to a hidden form.
document.getElementById("kwoteString").value = arrayAsString;
//checks output.
alert(document.kwoteForm.kwoteString.value);
}
$(document).ready(function() {
var txt = $('#txtlzr'); // The container in which to render the list
var options = {
duration: 5, // Time (ms) each blurb will remain on screen
rearrangeDuration: 5, // Time a character takes to reach its position
effect: 'random', // Animation effect the characters use to appear
centered: true // Centers the text relative to its container
}
txt.textualizer(COMMENTS_FOR_DISPLAY); // textualize it!
txt.textualizer('start'); // start
});
</script>
</body>
</html>
PHP:
<?php
$saveKwote = $_POST["kwoteString"];
echo saveKwote;
?>
由於某種原因,沒有什麼是迴盪!
我認爲這個錯字不在您的PHP代碼中? 'echo saveKwote;'應該是'echo $ saveKwote'; – Gazillion 2012-04-17 19:02:16
'error_reporting(E_ALL)'是你的朋友!!!! – 2012-04-17 19:04:19
它是一個TYPO !!!,感謝GAZILION。這很令人尷尬。 – 2012-04-17 19:06:29