Ajax form for receiving and posting student responses

This starter code shows how we can collect student responses to questions and then show the students other recent responses for them to compare with their answers. Unlike regular forms, there is not a need to leave the page. Data is collected in a database.

<!DOCTYPE html>
<html>
    <head>
        <title>Demandaro 18</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script>
            $(document).ready(function() {
                $("form").submit(function(event){
                    event.preventDefault();
                    var $form = $ (this),
                    url = $form.attr('action');
                    var values = $form.serialize();
                    $("#thereply").html(values);
                    $.post(url,values,
                    function(data) {
                        $('#thereply').html(data);
                    });
                }); 
            });

        </script>
    </head>
    <body>
        <h2>Faru demandojn por la jenaj respondoj.</h2>
        <div id="thereply">
            waiting for reply...
        </div>
        <form action="http://bazaesperanto.com/respondo.php">
            <input type="hidden" value="1001" name="chapter">
            <input type="hidden" value="1" name="qnum">
            1.  <input name="myresponse" size="120" type="text"/>
        </form> 
        <div>Jes, ĉiusomere.</div> 

        <form action="http://bazaesperanto.com/respondo.php">
            <input type="hidden" value="1001" name="chapter">
            <input type="hidden" value="2" name="qnum">
            2.  <input name="myresponse" size="120" type="text"/>
        </form> 
        <div>Kun siaj gepatroj kaj Heleno.</div> 

    </body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s