<table class="table_list" >
<caption>
填寫要更新的資料
</caption>
<tr>
<td class="align_c">無重新整理儲存</td>
<td >
<label>
<input name="ajaxdata" type="text" size="20" id="ajaxdata"/>
</label></td>
</tr>
<tr>
<td width="29%" class="align_c"> </td>
<td width="71%" ><label>
<input type="submit" name="button" onclick="return save();" value="提交" />
</label></td>
</tr>
</table>
<div id="www111cnnet"></div>
<script language="javascript教程">
var $=function(id) {
return document.getElementById(id);
}
function createXMLHttpRequest(){//建立XMLHttpRequest對象
if(window.ActiveXObject){//IE
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
return;
}
}else if(window.XMLHttpRequest){//Mozilla,firefox
try {
return new XMLHttpRequest();
} catch(e){
return;
}
}
}
function save(){//主調函數
var xmlHttp=createXMLHttpRequest();
var url = "/save.php教程";
var ajaxdata = $('ajaxdata').value;
if (ajaxdata ==''){
alert(' www.111cn.net提示你:請填寫資料 ');
return false ;
}
if (xmlHttp){
callback = getReadyStateHandler(xmlHttp);
xmlHttp.onreadystatechange = callback;
xmlHttp.open("POST", url,true);
xmlHttp.send(null);
}
}
function getReadyStateHandler(xmlHttp){//伺服器返回後處理函數
return function (){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
if (xmlHttp.responseText){
$('www111cnnet').innerHTML =xmlHttp.responseText;
}
}
}
}
}
</script>
<?
sava.php檔案
mysql教程_connect("localhost","root","root") or die('Database Server Uid or Password Error!');
mysql_select_db('ip') or die('data !');
mysql_query("SET NAMES 'gb2312'");//設定文檔與資料庫教程編碼一致就OK,否則會出亂碼
$data = $_POST['ajaxdata'];
if( empty( $data ) )
{
echo '你未提供資料';
}
else
{
$sql = "Insert text(data)value('$data')";
if( mysql_query( $sql ) )
{
echo '資料儲存成功';
}
else
{
echo '資料更新失敗';
}
}
?>
本站原創文章轉載註明來自www.111cn.net
*/