Được gửi bởi
ramang
Hic, nó là như thế này. Mình có 1 textfield và 1 button. Mình muốn khi người dùng nhập 1 rồi submit, trên trang web sẽ hiển thị 1. Tiếp đó nhập 2 rồi submit sẽ hiển thị 1 2. Nếu muốn sửa giá trị 2 vừa nhập thì nhấn nút back trên trình duyệt sau đó nhập 3 rồi submit để trên trang web sẽ hiển thị 1 3. Chỉ đơn giản vậy thôi. Nhưng mình nghĩ mãi không ra. Làm ơn chỉ giúp. Đang cần gấp!!!
Vất vả quá, mình làm thế này, bạn xem thử có hợp không nhé:
file index.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP, Submit, Simple Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#submitData').click(function(){
$.post('exec_data.php', {input_txt: $('#inputTxt').val()}, function(data){
$('#report').html(data);
});
return false;
});
});
</script>
</head>
<body>
<form id="frmData" action="">
<input type="text" name="txt" id="inputTxt" />
<input type="submit" value="submit" id="submitData" />
</form>
<p id="report"></p>
</body>
</html>
file exec_data.php
Code:
<?php
echo 'Import values: ' . $_POST['input_txt'] . ' to dababase successful.';
/*
$sql = "INSERT INTO table....";
$result = mysql_query($sql) ;
if ($result) {
echo 'Successful';
} else {
echo 'Fail';
}
*/
?>
Bookmarks