Feb 28, 2017

How to Make an AJAX Request with jQuery for HTML5 and CSS3 Programming

The primary purpose of an AJAX library like jQuery is to simplify AJAX requests for HTML5 and CSS3 programmers. It’s hard to believe how easy this can be with jQuery.

Preview of a HTML site using Ajax.

How to include a text file with AJAX

Check out this clean code:

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>ajax.html</title> <script type = "text/javascript"   src = "jquery-1.10.2.min.js"></script> <script type = "text/javascript"> $(document).ready(getAJAX); function getAJAX(){  $("#output").load("hello.txt"); } </script> </head> <body> <div id = "output"></div> </body></html>

The HTML is very clean. It simply creates an empty div called output.

This example does use AJAX, so if it isn’t working, you might need to remember some details about how AJAX works. A program using AJAX should be run through a web server, not just from a local file. Also, the file being read should be on the same server as the program making the AJAX request.

The load() mechanism described here is suitable for a basic situation where you want to load a plain-text or HTML code snippet into your pages.

Building a poor man’s CMS with AJAX

AJAX and jQuery can be a very useful way to build efficient websites, even without server-side programming. Frequently a website is based on a series of smaller elements that can be swapped and reused. You can use AJAX to build a framework that allows easy reuse and modification of web content.

A website created with Ajax and JQuery.

Although nothing is all that shocking about the page from the user’s perspective, a look at the code can show some surprises:

<!DOCTYPE html><html lang = "en"> <head> <meta charset = "UTF-8"> <title>CMS Using AJAX</title> <link rel = "stylesheet"   type = "text/css"   href = "cmsStd.css" /> <script type = "text/javascript"   src = "jquery-1.10.2.min.js"></script> <script type = "text/javascript">  $(init);  function init(){  $("#heading").load("head.html");  $("#menu").load("menu.html");  $("#content1").load("story1.html");  $("#content2").load("story2.html");  $("#footer").load("footer.html");  }; </script> </head> <body> <div id = "all">  <!-- This div centers a fixed-width layout →  <div id = "heading">  </div><!-- end heading div →  <div id = "menu">  </div> <!-- end menu div →  <div class = "content"   id = "content1">  </div> <!-- end content div →  <div class = "content"   id = "content2">  </div> <!-- end content div →  <div id = "footer">  </div> <!-- end footer div → </div> <!-- end all div → </body></html>

Look over the code, and you can see these interesting features:

  • The page has no content! All the divs are empty. None of the text shown in the screen shot is present in this document, but all is pulled from smaller files dynamically.

  • The page consists of empty named divs. Rather than any particular content, the page consists of placeholders with IDs.

  • It uses jQuery. The jQuery library is used to vastly simplify loading data through AJAX calls.

  • All contents are in separate files. Look through the directory, and you can see very simple HTML files that contain small parts of the page. For example, story1.html looks like this:

    <h2>Book I - Creating the HTML Foundation</h3><ol> <li>Sound HTML Foundations</li> <li>It's All About Validation</li> <li>Choosing your Tools</li> <li>Managing Information with Lists and Tables</li> <li>Making Connections with Links</li> <li>Adding Images</li> <li>Creating forms</li></ol>
  • The init() method runs on document.ready. When the document is ready, the page runs the init() method.

  • The init() method uses AJAX calls to dynamically load content. It’s nothing more than a series of jQuery load() methods.

This approach may seem like a lot of work, but it has some very interesting characteristics:

  • If you’re building a large site with several pages, you usually want to design the visual appearance once and reuse the same general template repeatedly.

  • Also, you’ll probably __have some elements that will be consistent over several pages. You could simply create a default document and copy and paste it for each page, but this approach gets messy. What happens if you __have created 100 pages according to a template and then need to change the header? You need to make the change on 100 different pages.

The advantage of the template-style approach is code reuse. Just like the use of an external style allows you to multiply a style sheet across hundreds of documents, designing a template without content allows you to store code snippets in smaller files and reuse them. All 100 pages point to the same menu file, so if you want to change the menu, change one file and everything changes with it.

Here’s how you use this sort of approach:

  1. Create a single template for your entire site.

    Build basic HTML and CSS to manage the overall look and feel for your entire site. Don’t worry about content yet. Just build placeholders for all the components of your page. Be sure to give each element an ID and write the CSS to get things positioned as you want.

  2. Add jQuery support.

    Make a link to the jQuery library, and make a default init() method. Put in code to handle populating those parts of the page that will always be consistent.

  3. Duplicate the template.

    After you have a sense of how the template will work, make a copy for each page of your site.

  4. Customize each page by changing the init() function.

    The only part of the template that changes is the init() function. All your pages will be identical, except they have customized init() functions that load different content.

  5. Load custom content into the divs with AJAX.

    Use the init()function to load content into each div.

This is a great way to manage content, but it isn’t quite a full-blown content-management system. Even AJAX can’t quite allow you to store content on the web. More complex content management systems also use databases rather than files to handle content. You’ll need some sort of server-side programming (like PHP) and usually a database (like mySQL) to handle this sort of work.

13 Keyboard Shortcuts for Common SketchUp Tools

SketchUp offers keyboard shortcuts for the tools you use most often as you create models. To select the tool you want, simply press the letter that’s indicated in the following table.

Tool Shortcut Key
Line L
Eraser E
Select Spacebar
Move M
Circle C
Arc A
Rectangle R
Push/Pull P
Offset O
Rotate Q
Scale S
Zoom Extents Shift+Z
Paint Bucket B

3 Timesaving Techniques for Using SketchUp

Creating a 3-D model takes time, but SketchUp makes it accessible and easy when compared to high-end modeling programs. As you create your models in SketchUp, you’ll come to appreciate the following timesaving techniques.

To divide an edge into a number of shorter edges:

  1. Right-click an edge with the Select tool.

  2. Choose Divide from the context menu that pops up.

  3. Type the number of segments you’d like and press Enter.

To resize your whole model based on one known measurement:

  1. Select the Tape Measure tool.

  2. Press Ctrl (Option on a Mac) until you don’t see a + next to your cursor.

  3. Measure a distance; click once to start measuring, and again to stop.

  4. Type a dimension for the distance you just measured and press Enter.

  5. Click Yes in the dialog box that pops up.

To set up your own keyboard shortcuts:

  1. Choose Window→Preferences (File→Preferences on the Mac).

  2. Click the Shortcuts panel.

13 Tips and Techniques for Using SketchUp

One of the best things about SketchUp is that you can use it to create 3-D models much more quickly than with other modeling programs. You can really turn up the speed on your creations with the following tips and techniques for using SketchUp tools.

To Do This Task Here’s the Best Way
Navigate
Orbit with your mouse Hold down scroll wheel
Zoom with your mouse Roll scroll wheel
Pan with your mouse Hold down Shift and the scroll wheel
Draw
Draw an edge a certain length with the Line tool Type a length and press Enter
Snip off an edge at the last place you clicked Press the Esc key
Lock your current direction with the Line tool Hold down the Shift key while drawing with the tool
Change the number of sides in a circle, arc, or polygon Type a number, then type s, and press Enter
Draw a circle or an arc of a certain radius Type a radius and press Enter after you draw a circle
Select with the Select tool
Add or subtract from what you’ve selected Hold down Shift
Select everything that isn’t hidden Press Ctrl+A (Command+A on the Mac)
Select everything inside a selection box Click and drag from left to right
Select everything touched by a selection box Click and drag from right to left
Select all faces with the same material Right-click and choose Select→All with Same Material
Move with the Move tool
Move a certain distance Type a distance and press Enter after you move
Force Auto-Fold (tell SketchUp it’s okay to fold) Press Alt (Command on the Mac)
Lock yourself in the blue (up and down) direction Press the up arrow or down arrow key
Copy with the Move and Rotate tools
Make a copy with the Move or Rotate tools Press Ctrl (Option on the Mac)
Make multiple copies in a row Make a copy, type a distance, type x, and press
Enter
Make multiple copies between Make a copy, type a number, type /, and press Enter
Hide and Smooth with the Eraser tool
Hide something Hold down Shift and click with the Eraser
Smooth something Ctrl+click with the Eraser (Option+click on the Mac)
Unsmooth something Hold down Shift+Ctrl and click with the Eraser (Shift+Option on
the Mac)
Push/Pull and Offset
Make a copy of the face you’re push/pulling Press Ctrl (Option on the Mac) and use the Push/Pull tool
Repeat the last distance you push/pulled Double-click a face with the Push/Pull tool
Repeat the last distance you Offset Double-click a face with the Offset tool
Scale with the Scale tool
Scale about the center Hold down Ctrl (Option on the Mac) while scaling
Scale uniformly (don’t distort) Hold down Shift while scaling
Scale by a certain factor Type a number and press Enter
Make something a certain size Type the size and the units and then press Enter
Apply materials with the Paint Bucket tool
Sample a material from a face Hold down Alt (Command on the Mac) and click the face with the
tool
Paint all faces that match the one you click Hold down Shift while you click
Create guides
Tell the Tape Measure or Protractor tool to create a guide Press Ctrl (Option on the Mac) and click with the tool
Walk around your model with the Walk tool
Walk through things Hold down Alt (Command on the Mac)
Run instead of walk Hold down Ctrl (Option on the Mac)
Get taller or shorter instead of walking Hold down Shift
Change your eye height Select the Look Around tool, type a height, and press
Enter
Change your field of view Select the Zoom tool, type a number, type deg, and press
Enter

SketchUp For Dummies Cheat Sheet

Like any 3-D modeling program, SketchUp offers different ways to do common tasks. In this Cheat Sheet, you’ll find tips on the best way to use SketchUp tools and to boost your productivity. Keyboard shortcuts also enable you to work quickly and easily in SketchUp, so you’ll uncover keyboard shortcuts for common tools.

13 Tips and Techniques for Using SketchUp

One of the best things about SketchUp is that you can use it to create 3-D models much more quickly than with other modeling programs. You can really turn up the speed on your creations with the following tips and techniques for using SketchUp tools.

To Do This Task Here’s the Best Way
Navigate
Orbit with your mouse Hold down scroll wheel
Zoom with your mouse Roll scroll wheel
Pan with your mouse Hold down Shift and the scroll wheel
Draw
Draw an edge a certain length with the Line tool Type a length and press Enter
Snip off an edge at the last place you clicked Press the Esc key
Lock your current direction with the Line tool Hold down the Shift key while drawing with the tool
Change the number of sides in a circle, arc, or polygon Type a number, then type s, and press Enter
Draw a circle or an arc of a certain radius Type a radius and press Enter after you draw a circle
Select with the Select tool
Add or subtract from what you’ve selected Hold down Shift
Select everything that isn’t hidden Press Ctrl+A (Command+A on the Mac)
Select everything inside a selection box Click and drag from left to right
Select everything touched by a selection box Click and drag from right to left
Select all faces with the same material Right-click and choose Select→All with Same Material
Move with the Move tool
Move a certain distance Type a distance and press Enter after you move
Force Auto-Fold (tell SketchUp it’s okay to fold) Press Alt (Command on the Mac)
Lock yourself in the blue (up and down) direction Press the up arrow or down arrow key
Copy with the Move and Rotate tools
Make a copy with the Move or Rotate tools Press Ctrl (Option on the Mac)
Make multiple copies in a row Make a copy, type a distance, type x, and press
Enter
Make multiple copies between Make a copy, type a number, type /, and press Enter
Hide and Smooth with the Eraser tool
Hide something Hold down Shift and click with the Eraser
Smooth something Ctrl+click with the Eraser (Option+click on the Mac)
Unsmooth something Hold down Shift+Ctrl and click with the Eraser (Shift+Option on
the Mac)
Push/Pull and Offset
Make a copy of the face you’re push/pulling Press Ctrl (Option on the Mac) and use the Push/Pull tool
Repeat the last distance you push/pulled Double-click a face with the Push/Pull tool
Repeat the last distance you Offset Double-click a face with the Offset tool
Scale with the Scale tool
Scale about the center Hold down Ctrl (Option on the Mac) while scaling
Scale uniformly (don’t distort) Hold down Shift while scaling
Scale by a certain factor Type a number and press Enter
Make something a certain size Type the size and the units and then press Enter
Apply materials with the Paint Bucket tool
Sample a material from a face Hold down Alt (Command on the Mac) and click the face with the
tool
Paint all faces that match the one you click Hold down Shift while you click
Create guides
Tell the Tape Measure or Protractor tool to create a guide Press Ctrl (Option on the Mac) and click with the tool
Walk around your model with the Walk tool
Walk through things Hold down Alt (Command on the Mac)
Run instead of walk Hold down Ctrl (Option on the Mac)
Get taller or shorter instead of walking Hold down Shift
Change your eye height Select the Look Around tool, type a height, and press
Enter
Change your field of view Select the Zoom tool, type a number, type deg, and press
Enter

3 Timesaving Techniques for Using SketchUp

Creating a 3-D model takes time, but SketchUp makes it accessible and easy when compared to high-end modeling programs. As you create your models in SketchUp, you’ll come to appreciate the following timesaving techniques.

To divide an edge into a number of shorter edges:

  1. Right-click an edge with the Select tool.

  2. Choose Divide from the context menu that pops up.

  3. Type the number of segments you’d like and press Enter.

To resize your whole model based on one known measurement:

  1. Select the Tape Measure tool.

  2. Press Ctrl (Option on a Mac) until you don’t see a + next to your cursor.

  3. Measure a distance; click once to start measuring, and again to stop.

  4. Type a dimension for the distance you just measured and press Enter.

  5. Click Yes in the dialog box that pops up.

To set up your own keyboard shortcuts:

  1. Choose Window→Preferences (File→Preferences on the Mac).

  2. Click the Shortcuts panel.

13 Keyboard Shortcuts for Common SketchUp Tools

SketchUp offers keyboard shortcuts for the tools you use most often as you create models. To select the tool you want, simply press the letter that’s indicated in the following table.

Tool Shortcut Key
Line L
Eraser E
Select Spacebar
Move M
Circle C
Arc A
Rectangle R
Push/Pull P
Offset O
Rotate Q
Scale S
Zoom Extents Shift+Z
Paint Bucket B

MWC 2017: Samsung Press Conference

12:57PM EST - We're here at Samsung's MWC 2017 press conference.

12:57PM EST - Matt on text, Anton on photos

12:58PM EST - Ian is here too, but he's busy writing up the Samsung news article.

12:58PM EST - After walking 1.2 miles from the LG press conference to the Huawei event, I couldn’t get in because the building was at capacity.

12:59PM EST - The Wi-Fi here is dead. We're uploading pics via 4G

01:00PM EST - Samsung usually announces its next Galaxy phone at MWC, but it already stated that it’s not announcing the Galaxy S8 here.

01:00PM EST - Instead, this event should feature some new tablets.

01:00PM EST - As such, this event is much smaller and less ostentatious than previous MWC events.

01:01PM EST - Sorry for the quality of the photos. We're sitting towards the back of the room.

01:04PM EST - It should be starting soon. Samsung's running a little late.

01:05PM EST - Hopefully it starts before I fall asleep

01:08PM EST - I need more coffee

01:11PM EST - I've been listening to the same song playing in a loop for 30 minutes

01:12PM EST - There __have not been many interesting Android tablets lately

01:14PM EST - Most of the compelling high-end tablets are running Windows 10

01:18PM EST - Apparently there's a technical difficulty with the projector

01:22PM EST - Here we go!

01:23PM EST - Showing a video about quality assurance testing. Odd way to start a press conference

01:24PM EST - Still trying to assuage people's fears about Note7 I guess

01:25PM EST - "You __have to give people what they want"

01:25PM EST - Reflecting on the past 6 months

01:26PM EST - Determined to correct past mistakes

01:26PM EST - Wants to regain customers' trust

01:26PM EST - Samsung has implemented an 8-point battery safety check and battery safety advisory group

01:27PM EST - A protestor was just asked to get off the stage

01:28PM EST - Thanking customers for remaining loyal to Samsung

01:28PM EST - Now looking to the future

01:28PM EST - New network technology, tablets, VR

01:28PM EST - First up: 5G

01:29PM EST - Tim Baxtor, President & COO Samsung America, on stage

01:30PM EST - Connecting devices. IoT

01:30PM EST - Connect everything!

01:31PM EST - Samsung has invested heavily in 5G

01:31PM EST - Talking about how great 5G is

01:32PM EST - Fast, low-latency, ubiquitous

01:32PM EST - Samsung launching its 5G network portfolio

01:33PM EST - Infrastructure, 5G radio, and 5G home router for consumers

01:33PM EST - 5G in the home instead of fiber

01:33PM EST - "Modem SoC" That's a pretty generic name

01:34PM EST - Spokesperson from Verizon on stage

01:35PM EST - Samsung is working with Verizon on 5G network trials

01:36PM EST - Now doing customer trials

01:36PM EST - Will begin in the next 60 days

01:38PM EST - Involves interoperability testing between devices and deployed network

01:38PM EST - It sounds like these trials are for fixed wireless applications

01:39PM EST - Moving on to tablets

01:40PM EST - The role of the tablet has become less defined

01:40PM EST - Most tablet usage takes place in the home

01:40PM EST - This usage still requires mobility

01:41PM EST - Most people see tablets as entertainment devices

01:41PM EST - Samsung is introducing 2 new tablets

01:42PM EST - Not just for entertainment. Can also be for work

01:42PM EST - Samsung Galaxy Tab S3

01:43PM EST - Cue slick product video

01:44PM EST - A tablet for entertainment and productivity

01:44PM EST - Glossy glass back

01:44PM EST - alumimum frame

01:44PM EST - silver and black colors

01:44PM EST - 429 grams

01:45PM EST - Ships with Android 7

01:45PM EST - Qualcomm Snapdragon SoC

01:45PM EST - 9.7" QXGA SAMOLED display

01:45PM EST - 97% of DCI-P3

01:46PM EST - Supports HDR content

01:46PM EST - blue light filter for reading

01:47PM EST - It includes Qualcomm's Game Center software to mute notifications while gaming

01:47PM EST - Includes 4 speakers tuned by AKG

01:48PM EST - Auto rotate speakers: audio changes when tablet is shifted between portrait and landscape

01:48PM EST - "a 9.7-inch home theater solution"

01:49PM EST - Claimed 12 hour battery life (video playback)

01:49PM EST - LTE & Wi-Fi connectivity

01:50PM EST - There's a keyboard cover and S Pen for productivity and taking notes

01:50PM EST - S Pen based on Wacom tech

01:50PM EST - Galaxy Tab S3 includes the S Pen in the box

01:51PM EST - S Pen does not use batteries and does not require charging

01:51PM EST - Pressure sensitive

01:52PM EST - There's a new special edition S Pen by Staedtler modeled after a pencil

01:53PM EST - Now for the next product

01:54PM EST - Samsung Galaxy Book

01:54PM EST - "for the user who needs to get things done"

01:55PM EST - Windows 10 2-in-1 device

01:55PM EST - all aluminum chassis with a fan inside

01:58PM EST - Intel Core i5-7200U inside

01:58PM EST - 12" has up to 8GB RAM and 256GB storage

01:59PM EST - Comes with 2 USB Type-C ports on same edge

01:59PM EST - LTE connectivity

01:59PM EST - fast-charging battery with a claimed 10.5 hours of battery life

02:00PM EST - Microsoft representative on stage to discuss collaboration on Windows devices

02:01PM EST - The Galaxy Book seems to compete with Microsoft's Surface and Huawei's MateBook

02:01PM EST - [my wrist is cramping]

02:02PM EST - emphasizing Windows 10 security

02:02PM EST - can use Windows Hello with Galaxy Book

02:03PM EST - Office 365 + Windows 10 for productivity

02:03PM EST - Full S Pen functionality and features (Air Command, etc) on Windows

02:04PM EST - Adobe Photoshop recognizes S Pen for enhanced functions

02:05PM EST - Adobe on stage demoing S Pen with Photoshop

02:06PM EST - The S Pen inking is smooth and tracks with the pen well

02:07PM EST - The keyboard cover (included) is backlit (powered by the tablet, no battery) and has similar key travel to laptop

02:08PM EST - Tablet connects to keyboard magnetically

02:08PM EST - Samsung Flow: software that provides integration between Galaxy Book and other Galaxy devices

02:08PM EST - Unlock Galaxy Book with fingerprint sensor on Galaxy phone

02:09PM EST - Notifications from phone show up on Galaxy Book

02:09PM EST - You cannot take or receive calls on Galaxy Book, though, like you can with MacBook/iPhone

02:09PM EST - That's it for tablets

02:10PM EST - Now VR

02:10PM EST - Gear VR has "democratized the VR experience"

02:11PM EST - New Samsung Gear VR with handheld controller with touchpad from Occulus

02:12PM EST - hand tracking opens up new experiences

02:12PM EST - Gear VR Control will come with Gear VR

02:12PM EST - Just one more thing!

02:13PM EST - Galaxy S8 teaser in progress

02:13PM EST - 3/29/2017

02:14PM EST - Galaxy Unpacked event for S8

02:14PM EST - And that's it!

02:15PM EST - Time for some hands-on time with the new tablets