Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Working with Linux ??? Quick Hacks for the Command Line

You're reading from   Working with Linux ??? Quick Hacks for the Command Line Command line power like you've never seen

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781787129184
Length 222 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Bogdan Vaida Bogdan Vaida
Author Profile Icon Bogdan Vaida
Bogdan Vaida
Petru I»ôfan Petru I»ôfan
Author Profile Icon Petru I»ôfan
Petru I»ôfan
Arrow right icon
View More author details
Toc

The spot webserver


We have prepared a basic demo html file that contains a button, a div, a jquery function (for helping us do some ajax calls), and a script that will try to load static content from our server and put the content inside the div tag. The script is trying to load a simple text file on the disk, /file:

If we open this file inside our browser, we can see the page content:

Clicking on the button generates a javascript error. It is telling us that we want to do a cross-origin request, which is not allowed by default by the browser. This is to prevent cross-site scripting attacks. What we need to do in order to test our javascript code is to serve this file in an HTTP server.

In order to start an HTTP server in the same folder as the file, we type the following command:

python -m SimpleHTTPServer

This is a basic Python module that opens port 8000 on localhost, serving only static content (so, no, you can't use it for php). Let's open the address in the browser:

Click on the Click...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime