• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 713
  • Last Modified:

Ajax + jQuery - simple example of editing form

Hi,

Anyone can provide me an example with how to do one input form based on ajax and jQuery. I'd like to see a form where a user puts value to input section, clicks 'save' and change the value and again clicks save and all these data were sent to DB without refreshing page.
0
spandor
Asked:
spandor
1 Solution
 
OrTzabaryCommented:
Example included...
PHP Page (save2db.php):
<?php
$name = $_POST['name'];
 
$ins_res = mysql_query("INSERT INTO table SET field = '$name'");
?>
 
HTML(+Ajax) Page:
<html>
<head>
<script type="text/javascript">
function Save() {
var namefield = $("#name").val();
$.post("save2db.php", { name: namefield },
  function(data){
    alert("Data Saved: " + data);
  });
 
}
</script>
</head>
<body>
<input type="text" id="name" />
<input type="button" onclick="Save();" />
</body>
</html>

Open in new window

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now