Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

Practice exercises CHAPTER 8 385



  1. If you see a pop-up prompt stating that Windows Firewall has blocked some features,
    as shown in Figure 8-13, make sure both check boxes are selected and click the Allow
    Access button to continue.


FIGURE 8-13 Accepting both options when prompted


  1. After starting the website, open the web browser and type http://localhost:8080 to
    see the Contoso home page.
    Be sure to clear the cache for the page by pressing Ctrl+F5. You should see the
    Contoso home page and be able to click the link for the ContactUs page to see that
    page.

  2. Modify the index.js file so that a POST to /ContactMessage returns a thank you mes-
    sage to the customer and logs a small message to the console window as follows.
    app.post('/ContactMessage', function (request, response) {
    var form = new formidable.IncomingForm();
    form.parse(request, function (err, fields) {
    var lastName = fields.lastName,
    firstName = fields.firstName,
    email = fields.email,
    message = fields.message;


response.writeHead(200, { 'Content-Type': 'text/html' });
response.write('Thank you, ' + firstName + ' ' + lastName + '<br/>');
response.write('We will contact you at ' + email + '<br/>');
response.end('Your message: ' + message + '<br />');
console.log('Handled request for ' + firstName + ' ' + lastName);
});
});


  1. In Visual Studio, open the ContactUs.html page and change the
    element to
    POST to the /ContactMessage URL.

Free download pdf