<script language='javascript' type='text/javascript'>
function ajaxFunction(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try{
ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e){
// Something went wrong
alert('Your browser broke!');
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('pagecomments');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var message = document.getElementById('message').value;
var wpm = document.getElementById('wpm').value;
var queryString = '?message=' + message + '&wpm=' + wpm;
request.open("POST", ajaxprofilechat.php, true);
http.send(null);
}
</script>
你好,我想這個劇本,我從AJAX GET方法有POST方法進行轉換,因爲我認爲它會解決的一個我在我的網站上遇到的問題。不過,我是非常非常新手的ajax編碼,雖然我試圖轉換爲POST,但由於此腳本無法正常工作,因此出現錯誤。有人可以幫助我解決這個問題,我有嗎?我想要做的就是使用POST方法。使用POST時甚至需要使用變量和查詢字符串?任何幫助將不勝感激。謝謝你的時間!我無法將我的ajax「GET」,以「POST」
這裏是ajaxprofilechat
mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
$age = $_POST['message'];
$wpm = $_POST['wpm'];
$age = mysql_real_escape_string($age);
$wpm = mysql_real_escape_string($wpm);
$chatname6 = ($_SESSION['username']);
$message6 = $_GET['site_message'];
$month6 = date("F");
$dayofmonth6 = date("d");
$year6 = date("Y");
$date10 = "$month6 $dayofmonth6 $year6";
$hours6 = date("g");
$min6 = date("i");
$sec6 = date("s");
$amorpm6 = date("A");
$time6 = "$hours6:$min6 $amorpm6";
if (strlen($age)>4)
{
mysql_query("INSERT INTO guestbook VALUES ('','$wpm','$chatname6','$age','$date10','$time6')");
echo " <h80><b>Comment Posted</b></h80><p><p>";
}
else
{
echo " <h80><b>Your comment must be greater than four characters</b></h80><p>";
}
?>
你應該從瞭解ajax開始:http://www.w3schools.com/ajax/default.asp – MatTheCat