Ajax + jQuery - simple example of editing form

Posted on 2009-02-20
Last Modified: 2013-12-13

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.
Question by:spandor
    1 Comment
    LVL 3

    Accepted Solution

    Example included...
    PHP Page (save2db.php):
    $name = $_POST['name'];
    $ins_res = mysql_query("INSERT INTO table SET field = '$name'");
    HTML(+Ajax) Page:
    <script type="text/javascript">
    function Save() {
    var namefield = $("#name").val();
    $.post("save2db.php", { name: namefield },
        alert("Data Saved: " + data);
    <input type="text" id="name" />
    <input type="button" onclick="Save();" />

    Open in new window


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now