Advertisement
Guest User

Untitled

a guest
Jan 4th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // All the code below will be run once the page content finishes loading.
  2.  
  3. document.addEventListener('DOMContentLoaded', function () {
  4.     'use strict';
  5.     // process the form when "submit" button is clicked
  6.     $('form[name=urlForm]').submit(function (event) {
  7.         // get the data in the form
  8.         // there are many ways to get this data using jQuery (you can use the class or id also)
  9.         var formData = {
  10.             //element[attribute=value]
  11.             'name': $('input[name=url]').val(),
  12.         };
  13.         //this is the request
  14.         console.log("your request data -> ", formData.name);
  15.         // process the form
  16.         $.ajax({
  17.             type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
  18.             url: '/createShorter', // the url where we want to POST
  19.             data: formData, // our data object
  20.             dataType: 'json', // what type of data do we expect back from the server
  21.             encode: true
  22.         })
  23.  
  24.             // using the 'done' promise callback
  25.             .done(function (data) {
  26.                 // log data to the console so we can see
  27.                 console.log("done: ", data.shortID);
  28.                 $('#url-output').text("http://url.domain.me/" + data.shortID);
  29.                 // here we will handle errors and validation messages
  30.             });
  31.         // stop the form from submitting the normal way and refreshing the page
  32.         event.preventDefault();
  33.     });
  34.  
  35.     //wire up button
  36.     $(document).ready(function () {
  37.         $("#submit").click(function () {
  38.             $("#myModal").modal();
  39.         });
  40.     });
  41.  
  42.     //placeholder text fades in/out when clicked
  43.     $('.smallInputBox').data('holder', $('.smallInputBox').attr('placeholder'));
  44.  
  45.     $('.smallInputBox').focusin(function () {
  46.         $(this).attr('placeholder', '');
  47.     });
  48.  
  49.     $('.smallInputBox').focusout(function () {
  50.         $(this).attr('placeholder', $(this).data('holder'));
  51.     });
  52.  
  53. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement