At the end of my last post, I've posted my email for you to send your web development/ coding questions and inquiries:
The nice thing about it? You can see it but spambots can't! That means that the email address posted won't be flooded with pesky spams or other what-have-you.
Copy/ paste <a href="mailto:john.doe@nowhere.com">email me</a> on the input box provided
Click Get obfuscated code button
The resulting code is displayed. Select the code and copy. You may click Select All link.
View the generated code
Enter the CSS below on the web page where the email link will appear:
<style>
#method1 b {
display:none;
}
Going back to the generated obfuscated code, copy/paste it on the bottom end of web page. This may be placed right before the </body> tag.
Next, we put in the HTML for the email link. From the CSS, we see that anything placed inside the <b> tag within any element tag of ID 'method1' will not be displayed at all. Therefore, we can write HTML with such tags to confuse spambots crawling our website.
The HTML, <p><span id="method1">joh<b>r</b>ndoe@g<b>wma</b>mail.com</span></p>, will only be seen by Spambot as it is, but will output on browser as:
The obfuscated code will show the email link below the email address:
The full HTML
<html>
<head>
<title>Hiding Email from Spambots</title>
<style>
#method1 b {
display:none;
}
</style>
</head>
<body>
<p><span id="method1">joh<b>r</b>ndoe@no<b>wma</b>where.com</span></p>
<script type="text/javascript">
<!--
var s="=b!isfg>#nbjmup;kpio/epfAopxifsf/dpn#?fnbjm!nf=0b?";
m=""; for (i=0; i<s.length; i++) m+=String.fromCharCode(s.charCodeAt(i)-1); document.write(m);
//-->
</script>
<noscript>
You must enable JavaScript to see this text.
</noscript>
</body>
</html>
Got web development stuffs you want me to help you out? Email it to me at junrahsy.dolor@gwmamail.com and I'll be more than happy to blog about it with my inputs.
On this post, I will provide a knowledge share on how to use JQuery's $.ajax method to perform an HTTP asynchronous request. A front-end HTML page will pass an AJAX request to a back-end, which in return, returns a response in JSON format.
For this sample, I will use three basic files:
index.html
This will be the front-end page to make the AJAX request using JQuery $.ajax method.
jquery-1.11.1.min.js
This will contain all JQuery functionality to my JavaScript codes. Ypu may download the file on this link: http://jquery.com/download/
backend.php
I will be using PHP to handle the front-end request. This will accept the request from and returns an output in JSON format
A screen shot is shown below:
The index.html page will show a form with two input text boxes. The values entered in the input boxes will be submitted to the back-end, which in turn, will be concatenated. This may be a simple activity, but take note that the back end can do much more sophisticated actions.
The process button will trigger the AJAX call. The "result here" text will serve as the placeholder for the returned output.
The full code on the index.html page is as follows
Now we will go over each part of the JQuery code...
The 'process' button serves as the trigger point of the request- meaning, once this is clicked, the AJAX request starts to process.
The 'process' button as an ID of 'process':
Once the button is clicked, the JQuery code below is triggered.
The first step the triggered code will do is get the values stored in the input text boxes:
The input boxes haves ID's have names of 'val1' and 'val2' respectively. The .val() on the selectors for the input boxes picks up the values entered as soon as the 'process' button is clicked. The values are stored to corresponding variables:
The JQuery $.ajax method is called with the following settings:
url
type
data
dataType
success
error
Let's go through each settings:
The url specifies the back-end page the request will be sent to. In this case, we will use PHP to handle the request:
The type specifies if we are submitting using post or get request. In this sample, I've used post.
The data contains the values to be sent on post request in key value pair format to the settings url, backend.php:
In the screen shot below, I entered values on the input text boxes as follows:
The backend.php will combine the values and output a response in JSON. Given the values in the input text entries, the response output will be:
The dataType specifies the returned format of the response output- this will be in JSON.
The success contains a function handler if the AJAX request went well. My sample code will generate alerts for returned JSON response output and display one response on the placeholder for 'result here'.
Lastly, the error provides a handler in case the AJAX call did not went well:
That completes the sample code. Putting in all together, let's have a sample run:
We enter values on the input boxes and click the 'process' button. This will trigger the $.ajax call
The $.ajax call is successful and the output is displayed:
So there we have it, a sample $.ajax call to get JSON response.
One of the useful hacks I've come across is the syntax highlighter by Alex Gorbatchev. Since I'm on blogger, I am restricted to not being able to install plug-ins. Hence, the hack I am using.
I can emphasize PHP codes such as:
As well as JavaScript codes:
With that, I say that we're now in business and can move to the next topics!
Welcome to my just published blog site on web development.The blog title Web Code Do: The Way of The Intercepting Code was taken after Bruce Lee's Jeet Kune Do: The Way of The Intercepting Fists.
I'll start off this blog with some tips on JavaScript- this includes JQuery, AJAX, JSON. I'll be looking at Angular JS as we go along.
I'll also tackle what's hot (and what's not) in web development- compare trends or just share my inputs.
If you have some web coding/ development questions, feel free to post your comments....