javascript:
function insert_data(pno,id){
var answer = confirm(txt);
if (answer){
var b = "#button"+id; //button的id
$.ajax({
beforeSend: function(){ //ajax發送前做
$(b).attr('disabled',true);
},
type:"POST", //ajax用POST的方式
url:"test.php", //url
async: false,
data:"no="+pno, //傳到url的值
success: function(msg){ //ajax成功時做
if (msg == ""){
msg = "更新資料完成!";
}else{
msg = unescape(msg); //把utf-8轉成big5
}
alert(msg);
},
error: function(){ //ajax失敗時做
alert("修改資料發生錯誤,請再試一次!");
},
complete: function(){ //ajax完成時做
$(b).attr('disabled',false);
}
});
}
}
Html:
<input type="button" name="button1" id="button1>" value="更新" onclick="insert_data('123'1);">
PHP:
$no = $_POST["no"];
echo iconv("big5","utf-8","編號為:".$no); //big5轉utf-8
javascrip中文轉碼可參考:http://werdna1222coldcodes.blogspot.com/2008/12/javascriptescape-encodeuri.html
沒有留言:
張貼留言