Permalink
Browse files

Beginning a layout of the public facing page.

  • Loading branch information...
1 parent 0a6832e commit e9ed77cb8c0eedc2346be7cae5594e42d790ee02 @emasters committed Mar 24, 2012
Showing with 32 additions and 12 deletions.
  1. +28 −12 index.php
  2. +4 −0 js/jquery-1.7.2.min.js
View
@@ -2,22 +2,38 @@
<html>
<title>URL shortener</title>
<meta name="robots" content="noindex, nofollow">
+<script type="text/javascript" src="./js/jquery-1.7.2.min.js"></script>
+
</html>
<body>
-<form method="post" action="shorten.php" id="shortener">
-<label for="longurl">URL to shorten</label> <input type="text" name="longurl" id="longurl"> <input type="submit" value="Shorten">
+<form action="shorten.php" id="shortener">
+<label for="longurl">URL to shorten</label>
+<input type="text" name="longurl"> <input type="submit" value="Shorten">
</form>
-</form>
-<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+<div id="shorturl"></div>
+
<script type="text/javascript">
-$(function () {
- $('#shortener').submit(function () {
- $.ajax({data: {longurl: $('#longurl').val()}, url: 'shorten.php', complete: function (XMLHttpRequest, textStatus) {
- $('#longurl').val(XMLHttpRequest.responseText);
- }});
- return false;
- });
-});
+window.onload = (function(){
+try{
+/* attach a submit handler to the form */
+ $("#shortener").submit(function(event) {
+
+ /* stop form from submitting normally */
+ event.preventDefault();
+
+ /* get some values from elements on the page: */
+ var $form = $( this ),
+ term = $form.find( 'input[name="longurl"]' ).val(),
+ url = $form.attr( 'action' );
+
+ /* Send the data using post and put the results in a div */
+ $.post( url, { longurl: term },
+ function( data ) {
+ $( "#shorturl" ).empty().append( data );
+ }
+ );
+ });
+}catch(e){}});
</script>
</body>
</html>
Oops, something went wrong.

0 comments on commit e9ed77c

Please sign in to comment.