我當前的代碼,我有我的網站是在底部以下,我會很快transfering代碼到我profile.php :)阿賈克斯如何發送一個形式,沒有它重裝
test.php的
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js">
</script>
<script type="text/javascript" >
$(function() {
$("#ntb").click(function() {
var nt = $("#nt").val();
var data=$('#nt').serialize();
if(nt=='')
{
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{
$.ajax({
type: "POST",
url: "../ajax/post.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
});
</script>
<form method="post" name="form">
<input id="nt" name="nt" type="text" />
<input type="submit" style="display:block;" name='ntb' id='ntb' class="Buttonchat" value="Post" />
</form>
<div>
<span class="error" style="display:none"> Please Enter Valid Data</span>
<span class="success" style="display:none"> Registration Successfully</span>
</div></form>
上面這段代碼是Ajax和HTML,當我在阿賈克斯,但是當我剛纔的HTML和PHP它張貼到數據庫,IDK的爲什麼雖然:(
真的不工作。 ./ajax/post.php
<?php
include '../core/init.php';
if(isset($_POST['nt']) && isset($_POST['ntb'])){
mysql_query("INSERT INTO `post` (`myid`, `text`) VALUES ('".$_SESSION['id']."', '".mysql_real_escape_string($_POST['nt'])."')");
}
?>
以上是我的PHP發佈的數據,該工程100%:) 謝謝您的幫助
是的,但我如何得到它,因此它可以直接通過數據庫,而無需使頁面重新加載? – Bob
我增加了更多的代碼; 'some_php_page.php'。 PS-不要忘記給幫助你的用戶增加聲望,並在你解決問題時接受正確的答案。 – Andrew