JS/JQ:
Kod
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Quick JQuery Ajax Request</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var ajaxSubmit = function(formEl) {
var url = $(formEl).attr('action');
var data = $(formEl).serializeArray();
$.ajax({
url: process.php,
data: data,
dataType: 'json',
success: function() {
alert('form has been posted successfully');
}
});
return false;
}
</script>
</head>
<body>
<form method="post" action="process.php">
Value: <input type="text" name="my_value" />
<input type="submit" name="form_submit" value="Go" />
</form>
</body>
</html>
<html>
<head>
<title>Quick JQuery Ajax Request</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var ajaxSubmit = function(formEl) {
var url = $(formEl).attr('action');
var data = $(formEl).serializeArray();
$.ajax({
url: process.php,
data: data,
dataType: 'json',
success: function() {
alert('form has been posted successfully');
}
});
return false;
}
</script>
</head>
<body>
<form method="post" action="process.php">
Value: <input type="text" name="my_value" />
<input type="submit" name="form_submit" value="Go" />
</form>
</body>
</html>
PHP:
Kod
<?php
function post($key) {
if (isset($_POST[$key]))
return $_POST[$key];
return false;
}
$cxn = mysql_connect('localhost', 'root', '');
if (!$cxn)
exit;
mysql_select_db('baza3', $cxn);
if (!post('my_value'))
exit;
$val = mysql_real_escape_string(post('my_value'), $cxn);
$sql = 'insert into data (z1) values ("'.$val.'")';
$result = mysql_query($sql, $cxn);
?>
function post($key) {
if (isset($_POST[$key]))
return $_POST[$key];
return false;
}
$cxn = mysql_connect('localhost', 'root', '');
if (!$cxn)
exit;
mysql_select_db('baza3', $cxn);
if (!post('my_value'))
exit;
$val = mysql_real_escape_string(post('my_value'), $cxn);
$sql = 'insert into data (z1) values ("'.$val.'")';
$result = mysql_query($sql, $cxn);
?>