<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1797584766668995213</id><updated>2024-11-06T05:05:35.258+02:00</updated><category term="AJAX"/><category term="PHP"/><category term="jQuery"/><title type='text'>SIMON&#39;S NOTEBOOK</title><subtitle type='html'>A blog like notebook, you will get a variety of tutorials and tips. I am keeping my note and sharing to my fellow learners what I am learning.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-306077397636534299</id><published>2013-03-18T06:38:00.001+02:00</published><updated>2013-03-18T17:48:40.893+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>Auto complete using jQuery &amp; Ajax</title><content type='html'>&lt;h2&gt;The Idea&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
You want to ask the user to enter a name in the input text field, so that the moment the user types the
first character of a name, a suggestion box will appear that displays all the names beginning with the
character typed. You also want the names displayed in the suggestion box to have a hovering effect – so
that they become highlighted on moving the mouse pointer over them – and the clicked name to be
inserted in the input text field.
&lt;p&gt;

&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
Let’s create an HTML file that displays a label: ‘Enter userid’ and an input text field. Below the input text
field, we create two empty div elements that are assigned the class names: listbox and nameslist
respectively. The HTML file may appear as shown below:
&lt;/p&gt;
&lt;pre class=&quot;brush:html&quot;&gt;
&lt;form&gt;
    &lt;span class=&quot;label&quot;&gt;Enter user id&lt;/span&gt;
    &lt;input type=&quot;text&quot; name=&quot;userid&quot; class=&quot;userid&quot;/&gt;
    &lt;div class=&quot;listbox&quot;&gt;
        &lt;div class=&quot;nameslist&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/form&gt;
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
The div element of class listbox will be used for displaying a box and the div element nameslist will
be used for displaying the names with hovering effect. We define the style rules to be applied to the two
div elements in the style sheet file: style.css as shown here:
&lt;/p&gt;
&lt;pre class=&quot;brush:css&quot;&gt;
.listbox {
    position: relative;
    left: 10px;
    margin: 10px;
    width: 200px;
    background-color: #000;
    color: #fff;
    border: 2px solid #000;
}
.nameslist {
    margin: 0px;
    padding: 0px;
    list-style:none;
}
.hover {
    background-color: cyan;
    color: blue;
}
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
The jQuery code to now make our suggestion box appear when the user types the first character in
the input text field, and to make the clicked name (in the suggestion box) to appear in the input text field
automatically, is as shown here:
&lt;/p&gt;

&lt;pre class=&quot;brush:javascript&quot;&gt;
$(document).ready(function() {
    $(&#39;.listbox&#39;).hide();
    $(&#39;.userid&#39;).keyup(function () {
        var uid = $(&#39;.userid&#39;).val();
        var data=&#39;userid=&#39;+uid;

        $.ajax({
        type:&quot;POST&quot;,
        url:&quot;autocomplete.php&quot;,
        data:data,
        success:function(html) {
            $(&#39;.listbox&#39;).show();
            $(&#39;.nameslist&#39;).html(html);
            $(&#39;li&#39;).hover(function(){
                $(this).addClass(&#39;hover&#39;);
            },function(){
                $(this).removeClass(&#39;hover&#39;);
            });
            $(&#39;li&#39;).click(function(){
                $(&#39;.userid&#39;).val($(this).text());
                $(&#39;.listbox&#39;).hide();
            });
      }
    });
    return false;
  });
});
&lt;/pre&gt;
&lt;p class=&quot;aligned&quot;&gt;
The script file autocomplete.php, on the server, is designed to send the list of names as response, and
it should look like this:
&lt;/p&gt;
&lt;pre class=&quot;brush:php&quot;&gt;
    echo &#39;&lt;li&gt;Jackub&lt;/li&gt;&#39;;
    echo &#39;&lt;li&gt;Jenny&lt;/li&gt;&#39;;
    echo &#39;&lt;li&gt;Jill&lt;/li&gt;&#39;;
    echo &#39;&lt;li&gt;John&lt;/li&gt;&#39;;
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
Check out your site now. Try typing a name begins with &#39;J&#39;. &lt;br/&gt;&lt;b&gt;Booya!&lt;/b&gt; If everything&#39;s goes well I believe you will get a pop-up with a list of name begins with &#39;j&#39;.
&lt;/p&gt;
&lt;p class=&quot;aligned&quot;&gt;
Though this is not the best way of generating the autocomplete menu and obviously we will generate the autocomplete menu using data from the database, but I believe you get the idea. I will make another post where I&#39;m going to show how can we can grab the information(data) from the database and fill the autocomplete list with it. Knock me out if you have any question. Till then bye bye. 
&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/306077397636534299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2013/03/using-auto-complete-using-jquery-ajax.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/306077397636534299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/306077397636534299'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2013/03/using-auto-complete-using-jquery-ajax.html' title='Auto complete using jQuery &amp; Ajax'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-7875496238880313620</id><published>2013-03-18T06:05:00.005+02:00</published><updated>2013-03-18T06:39:50.837+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>Validating an Email Address usning jQuery &amp; Ajax</title><content type='html'>&lt;h2&gt;The Idea&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
You want the user to enter his email address and you want to use a server-side script to confirm that it is
a valid email address. This means that it must consist of alphanumericals, no symbols other than - and _
, plus it must contain both symbols . and @. If the email address is invalid, an error message should be
displayed to the user.
&lt;p&gt;

&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
Let’s make an HTML file that displays a label: ‘Enter email address’ and an input text field and a submit
button. The HTML file may appear as shown below:
&lt;/p&gt;
&lt;pre class=&quot;brush:html&quot;&gt;
&lt;form&gt;
    &lt;span class=&quot;label&quot;&gt;Enter email address&lt;/span&gt;
    &lt;input type=&quot;text&quot; name=&quot;emailadd&quot; class=&quot;emailadd&quot;/&gt;
    &lt;span class=&quot;error&quot;&gt;&lt;/span&gt;&lt;br/&gt;
    &lt;input type=&quot;submit&quot; id=&quot;submit&quot;/&gt;
&lt;/form&gt;
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
We can see in above HTML file that the input text field is assigned the class name emailadd for the
purpose of accessing it via jQuery code. Following the input text field, is an empty span element of class
error. The text to this span element will be assigned from the server generated response, if the user
enters an invalid email address.
&lt;/p&gt;
&lt;p class=&quot;aligned&quot;&gt;
In order to specify width to the label, input text field and color to the error message, we will make
use of the style rules written in the style sheet file from the solution we used in 8-3.
The jQuery code to invoke the server side script: validatemail.php for validating the email address
entered by the user is as shown below:
&lt;/p&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;
$(document).ready(function() {
    $(&#39;.error&#39;).hide();
    $(&#39;#submit&#39;).click(function () {
        var em = $(&#39;.emailadd&#39;).val();
        var data=&#39;emailadd=&#39;+em;
        $.ajax({
            type:&quot;POST&quot;,
            url:&quot;validatemail.php&quot;,
            data:data,
            success:function(html) {
                $(&#39;.error&#39;).show();
                $(&#39;.error&#39;).text(html);
            }
        });
        return false;
    });
});
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
The script file validatemail.php, on the server, is designed to check whether the email address of
the user is valid or not:
&lt;/p&gt;
&lt;pre class=&quot;brush:php&quot;&gt;
&lt;?php
$emid = $_POST[&#39;emailadd&#39;];
if (!eregi(&quot;^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$&quot;, $emid)){
    echo &quot;Invalid email address&quot;;
}
?&gt;
&lt;/pre&gt;

&lt;h2&gt;SOME SAMPLE I/O AND RESULT&lt;/h2&gt;
&lt;table style=&quot;background:#DDDDDD;&quot; cellspacing=&quot;2&quot; border=&quot;1&quot; cellpadding=&quot;10&quot;&gt;
&lt;tr&gt;
 &lt;th&gt;Input&lt;/th&gt;&lt;th&gt;Result/Output&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td&gt;john-123@yahoo&lt;/td&gt;&lt;td&gt;Not accepted/Invalid email address&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td&gt;john-123@yahoo.com&lt;/td&gt;&lt;td&gt;Accepted&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/7875496238880313620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2013/03/validating-email-address-usning-jquery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/7875496238880313620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/7875496238880313620'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2013/03/validating-email-address-usning-jquery.html' title='Validating an Email Address usning jQuery &amp; Ajax'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-3350604928583557581</id><published>2013-03-18T05:19:00.003+02:00</published><updated>2013-03-18T05:45:35.476+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>Validating a User Name Using Ajax</title><content type='html'>&lt;h2&gt;The Idea&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
You want to ask the user to enter a name and you want to use a server-side script to confirm that the
field is not left blank. If the user does not enter anything in the name field, then he should get an error
message.
&lt;p&gt;

&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
Let’s start by creating an HTML file that displays a label: ‘Enter your Name’ and an input text field and a
submit button. The HTML file may appear as shown below:
&lt;/p&gt;
&lt;pre class=&quot;brush:html&quot;&gt;
 &lt;body&gt;
  &lt;form&gt;
   &lt;span class=&quot;label&quot;&gt;Enter your Name&lt;/span&gt;
   &lt;input type=&quot;text&quot; name=&quot;uname&quot; class=&quot;uname&quot;/&gt; &lt;span class=&quot;error&quot;&gt; &lt;/span&gt;&lt;br&gt;
   &lt;input type=&quot;submit&quot; id=&quot;submit&quot;/&gt;
  &lt;/form&gt;
 &lt;/body&gt;
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
You can see here that the input text field is assigned class name uname for the purpose of accessing it
via jQuery code. Following the input text field is an empty span element of class error. The text to this
span element will be assigned from the server generated response – if the user leaves the input text field
blank.
&lt;/p&gt;
&lt;p class=&quot;aligned&quot;&gt;
In order to specify a width to the input text field label, and a color to the error message, we need to
write some style rules in the style sheet file:
&lt;/p&gt;
&lt;pre class=&quot;brush:css&quot;&gt;
.label {float: left; width: 120px; }
.uname {width: 200px; }
.error { color: red; padding-left: 10px; }
#submit { margin-left: 125px; margin-top: 10px;}
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
The jQuery code to invoke the server side script is below, which passes to validateuser.php. the
name entered by the user as a parameter, and displays an error message if the name is left blank by
the user:
&lt;/p&gt;

&lt;pre class=&quot;brush:javascript&quot;&gt;
$(document).ready(function() {
    $(&#39;.error&#39;).hide();
        $(&#39;#submit&#39;).click(function () {
            var name = $(&#39;.uname&#39;).val();
            var data=&#39;uname=&#39;+name;
            $.ajax({
                type:&quot;POST&quot;,
                url:&quot;validateuser.php&quot;,
                data:data,
                success:function(html) {
                    $(&#39;.error&#39;).show();
                    $(&#39;.error&#39;).text(html);
                }
            });
        return false;
     });
});
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
The script file validateuser.php itself, is on the server, and is meant for checking whether the name
of the user is not left blank. This code looks like this:
&lt;/p&gt;
&lt;pre class=&quot;brush:php&quot;&gt;
&lt;?php
if($_POST[&#39;uname&#39;] == &#39;&#39;){
    echo &quot;This field cannot be blank&quot;;
}
?&gt;
&lt;/pre&gt;

&lt;h2&gt;Validating user name using a regular expression&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
In the above solution, the user could enter anything when they were meant to be entering their user
name – including symbols. So let’s improve the server side script so we will only accept names that
consist of alphanumerical and underscore only. The script file validateuser.php can be modified as
shown here to achieve this for us:
&lt;/p&gt;
&lt;pre class=&quot;brush:php&quot;&gt;
&lt;?php
$name = $_POST[&#39;uname&#39;];
if (!eregi(&quot;^[a-z0-9_]+$&quot;, $name)){
    echo &quot;Invalid User Name&quot;;
}
?&gt;
&lt;/pre&gt;

&lt;h2&gt;SOME SAMPLE I/O AND RESULT&lt;/h2&gt;
&lt;table style=&quot;background:#DDDDDD;&quot; cellspacing=&quot;2&quot; border=&quot;1&quot; cellpadding=&quot;10&quot;&gt;
&lt;tr&gt;
 &lt;th&gt;Input&lt;/th&gt;&lt;th&gt;Result/Output&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td&gt;blank&lt;/td&gt;&lt;td&gt;Not accepted/This field cannot be blank&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td&gt;John&lt;/td&gt;&lt;td&gt;Accepted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td&gt;John-123&lt;/td&gt;&lt;td&gt;Not accepted/Invalid User Name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td&gt;John_123&lt;/td&gt;&lt;td&gt;Accepted&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/3350604928583557581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2013/03/validating-user-name-using-ajax.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/3350604928583557581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/3350604928583557581'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2013/03/validating-user-name-using-ajax.html' title='Validating a User Name Using Ajax'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-5930270113091393989</id><published>2012-08-05T04:23:00.000+03:00</published><updated>2012-08-05T04:23:06.917+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>Authentication With AJAX and PHP</title><content type='html'>&lt;h2&gt;THE IDEA&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
You want to ask the user to enter a name and password in a login form. If the name and password entered by the user matches with the contents in the server side script, your user should get a welcome message, otherwise a message should declare that they are an ‘Unauthorized user’.
&lt;p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
Let’s create an HTML file that displays two labels: ‘Enter your Name’ and ‘Enter your Password’ and two input text fields and a submit button and an empty div element. The HTML file should appear like this (place following code inside your body tag):
&lt;/p&gt;
&lt;pre class=&quot;brush:html&quot;&gt;
&lt;form&gt;
 &lt;label&gt;Enter your Name&lt;/label&gt;
 &lt;input type=&quot;text&quot; name=&quot;uname&quot; class=&quot;uname&quot;/&gt; &lt;br/&gt;
 &lt;label&gt;Enter your Password&lt;/label&gt;
 &lt;input type=&quot;password&quot; name=&quot;password&quot; class=&quot;passwd&quot;/&gt; &lt;br/&gt;
 &lt;input type=&quot;submit&quot; id=&quot;submit&quot;/&gt;
&lt;/form&gt;
&lt;div id=&quot;message&quot;&gt;&lt;/div&gt;
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
You can see that the HTML file contains the two input text fields that are assigned class names uname and passwd for the purpose of accessing them via jQuery code. Below the form is an empty div element of id message which we will be using for displaying the response generated by the server side script.
&lt;/p&gt;
&lt;h2&gt;AJAX and jQuery code: &lt;/h2&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;
$(document).ready(function() {
 $(&#39;#submit&#39;).click(function () {
  var name = $(&#39;.uname&#39;).val();
  var pwd = $(&#39;.passwd&#39;).val();
  var data=&#39;uname=&#39;+name+&#39;&amp;password=&#39;+pwd;
  $.ajax({
   type:&quot;POST&quot;,
   url:&quot;logincheck.php&quot;,
   data:data,
   success:function(html) {
    $(&quot;#message&quot;).html(html);
   }
  });
  return false;
 });
});
&lt;/pre&gt;
&lt;p class=&quot;aligned&quot;&gt;
The script file logincheck.php on the server validates the name and password entered by the user, and looks like this:
&lt;/p&gt;
&lt;h3&gt;logincheck.php&lt;/h3&gt;
&lt;pre class=&quot;brush:php&quot;&gt;
$name = trim($_POST[&#39;uname&#39;]);
$pswd = trim($_POST[&#39;password&#39;]);
if(($name==&quot;guest&quot;) &amp;&amp; ($pswd==&quot;jquery&quot;))
  echo &quot;Welcome &quot;. $name;
else
  echo &quot;Sorry you are not authorized&quot;;
&lt;/pre&gt;
&lt;p class=&quot;aligned&quot;&gt;
And we are ready to go! Check your working AJAX Authentication application. Too sleepy to write got to go, knock me if you are stuck anywhere, bye bye :)...
&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/5930270113091393989/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/08/authentication-with-ajax-and-php.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/5930270113091393989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/5930270113091393989'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/08/authentication-with-ajax-and-php.html' title='Authentication With AJAX and PHP'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-6871351392366793386</id><published>2012-08-04T17:57:00.003+03:00</published><updated>2012-08-05T04:08:01.085+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>Displaying Welcome Message With AJAX, jQuery and PHP</title><content type='html'>&lt;h2&gt;Idea&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
 You have a label, an input text field, and a submit button on a form, and you want a welcome message be
displayed to the user when they select the submit button – once they have entered their name in the
input text field.
&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p class=&quot;aligned&quot;&gt;
First of all, let’s create the HTML file that contains a label element, an input text field, a submit button, and an empty div element. The HTML file should look like this:
&lt;/p&gt;
&lt;pre class=&#39;brush:html&#39;&gt;
&lt;body&gt;
  &lt;form&gt;
    &lt;label&gt;Enter your Name&lt;/label&gt;
    &lt;input type=&quot;text&quot; name=&quot;uname&quot; class=&quot;uname&quot;/&gt; &lt;br/&gt;
    &lt;input type=&quot;submit&quot; id=&quot;submit&quot;/&gt;
  &lt;/form&gt;
  &lt;div id=&quot;message&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/pre&gt;

&lt;p class=&quot;aligned&quot;&gt;
You can see that the HTML file contains a label, an input text field, and a submit button nested in a form. The input text field is given the class name uname for the purpose of accessing it via our jQuery code that we’re about to write. Below the form is an empty div element of id message which we will use for displaying the welcome message to the user.
&lt;/p&gt;
&lt;p&gt;Before moving forward needless to mention that as I&#39;m going use jQuery functionality, you have import jQuery inside you head tag. You can download the latest release from &lt;a href=&quot;http://docs.jquery.com/Downloading_jQuery&quot;&gt;here&lt;/a&gt;. If you are not familiar with jQuery(Are you kidding me :@) visit &lt;a href=&quot;http://jquery.com/&quot;&gt;here&lt;/a&gt; to find out how to import jQuery to a site&lt;/p&gt;

&lt;h2&gt;The jQuery and AJAX code for our solution looks like this&lt;/h2&gt;
&lt;pre class=&#39;brush:javascript&#39;&gt;
$(document).ready(function(){
  $(&#39;#errorMsg&#39;).hide();

  $(&#39;#submit&#39;).click(function(){
   var name = $(&#39;.uname&#39;).val();
   //Checking if the input field is empty
   if( name != &#39;&#39;){
    var data = &#39;uname=&#39; + name;

    //Making the Ajax call
    $.ajax({
     type: &quot;POST&quot;,
     url: &quot;welcome.php&quot;, //url of you php file.
     data: data,
     success: function(html){
      $(&#39;#form&#39;).hide();
      $(&#39;#errorMsg&#39;).hide();
      $(&#39;#message&#39;).html(html);
     }
    });
   } else{//if the name field is empty showing th erroe message
    $(&#39;#errorMsg&#39;).show(&#39;fast&#39;);    
   }
   return false;
  });
 });
&lt;/pre&gt;

&lt;p class=&#39;aligned&#39;&gt;The script file welcome.php on the server is as follows&lt;p&gt;
&lt;h3&gt;welcome.php&lt;/h3&gt;
&lt;pre class=&quot;brush:php&quot;&gt;
$name = $_POST[&#39;uname&#39;];
echo &quot;Welcome &quot;. $name;
&lt;/pre&gt;
&lt;p class=&#39;aligned&#39;&gt;Don&#39;t forget to place this code in between a php tag &lt;br/&gt; Finally check out your functional AJAX page&lt;/p&gt;
&lt;p class=&quot;aligned&quot;&gt;
 Now we can simply make this job done by making a POST Request of jQuery.
&lt;/p&gt;
&lt;h3&gt;Making POST requests&lt;/h3&gt;
&lt;p class=&quot;aligned&quot;&gt;
For making POST requests to the server, we make use of the $.post() method, which you’ll use most generally when you want to make some modification in the information stored on the server. It fetches the data onto the server using POST HTTP request. It executes the script whose URL is specified along with the parameters passed (if any). This function also allows a single callback function to be specified that will be executed when the request is complete. Here’s the method and parameters:
&lt;/p&gt;
&lt;p&gt;&lt;b&gt;$.post(url, parameters, callback)&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;url&lt;/i&gt;&lt;/b&gt; is the server-side script to which we want to send request (via the POST
method)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;parameters&lt;/i&gt;&lt;/b&gt; is key/value pair that we want to be passed to the server-side script for processing&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;callback&lt;/i&gt;&lt;/b&gt; is the function that is invoked on completion of the request. It contains
two parameters, the first is the response from the server side script and the second
parameter is the status of execution&lt;/li&gt;
&lt;/ul&gt;
The previous JavaScript file can therefore be modified to use the $.post() method as follows:
&lt;/p&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;
  $(document).ready(function() {
    $(&#39;#submit&#39;).click(function () {
      var name = $(&#39;.uname&#39;).val();
      var data = &#39;uname=&#39; + name;
      $.post(
        &quot;welcome.php&quot;,
        data,
        function (html) {
          $(&#39;#message&#39;).html(html);
        }
      );
      return false;
    });
 });
&lt;/pre&gt;
&lt;p class=&quot;aligned&quot;&gt;
You can see that the $.post() method invokes the welcome.php file on the server and passes uname=name to it as a parameter (where name stores the name entered by the user) and the callback function displays the response (from the server) by assigning it to the div element of id message.
&lt;/p&gt;
&lt;p class=&quot;aligned&quot;&gt;
 Finally, please do remember that the server side script welcome.php must access the data from the $_POST array and not from the $_GET array beacuse the request sent is via the POST method:
&lt;/p&gt;
&lt;p class=&quot;aligned&quot;&gt;
And yes of course you can use the $.get() method in this same way but in that case you must access the data from the $_GET[] array. 
&lt;b&gt;$.get(url, parameters, callback)&lt;/b&gt;
&lt;/p&gt;
&lt;h3&gt;welcome.php for $.get() request&lt;/h3&gt;
&lt;pre class=&quot;brush:php&quot;&gt;
$name = $_GET[&#39;uname&#39;];
echo &quot;Welcome &quot;. $name;
&lt;/pre&gt;

&lt;p&gt;Thanks for your precious time on my content, I will appreciate you feedback. Don&#39;t burn you head if you have anything on it right now, just through it to me. xD &lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/6871351392366793386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/08/displaying-welcome-message-with-ajax.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/6871351392366793386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/6871351392366793386'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/08/displaying-welcome-message-with-ajax.html' title='Displaying Welcome Message With AJAX, jQuery and PHP'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-4183938949776211766</id><published>2012-07-30T15:06:00.001+03:00</published><updated>2012-07-30T15:26:52.455+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><title type='text'>Using AJAX as Navigational Tool [ Basic Ajax Example ]</title><content type='html'>&lt;script&gt;&lt;/script&gt;

&lt;body&gt;
&lt;p class=&#39;aligned&#39;&gt;
Following example shows a generic web page that loads in content via Ajax to display different information based on the link that has been clicked.
&lt;br/&gt;&amp;emsp;
Before you start, first you should go through these two content to understand how to use Ajax to create a XMLHttpRequest object and how to send a request to the server.&lt;br/&gt;
1 - &lt;a href=&#39;http://simonsnotes.blogspot.com/2012/07/creating-ajax-crossbrowser.html&#39; target=&#39;_blank&#39; style=&#39;color:blue;&#39;&gt;Creating AJAX XMLHttpRequest Object&lt;/a&gt;
&lt;br/&gt;
2 - &lt;a href=&#39;http://simonsnotes.blogspot.com/2012/07/sending-request-to-server.html&#39; target=&#39;_blank&#39; style=&#39;color:blue;&#39;&gt;Sending a Request to the Server&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;The home page or the base page where we will show our sub-pages using the magic of AJAX:&lt;/h3&gt;&lt;br/&gt;
&lt;h4&gt;Place it inside your &#39;head&#39; tag&lt;/h4&gt;
&lt;pre class=&#39;brush:javascript&#39;&gt;

&lt;title&gt;Sample Ajax Site&lt;/title&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
  var xmlhttp = false;

  //If, the activexobject is available, we must be using IE.
  if (window.ActiveXObject){
    xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); //for IE5, IE6 and older versions
  } else {
 //Else, we can use the native Javascript handler.
   xmlhttp = new XMLHttpRequest();  //for other latest browsers
  }
  
  //Creating the function to make ajax request
  function makerequest(serverPage, objID) {
    var obj = document.getElementById(objID);
    xmlhttp.open(&quot;GET&quot;, serverPage);
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
        obj.innerHTML = xmlhttp.responseText;
      }
    }
    xmlhttp.send(null);
  }

//--&gt;
&lt;/script&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;h4&gt;Place inside the body tag: &lt;/h4&gt;
P.S.: Please note that you have to call the function makerequest() once when the page is loading - &lt;br/&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyWvoO_uY6UIDHJB2FfvHxWJdmbRMfJvDvy7Zqj1nQ2iPx1z_Tq7mNxDZ8HkBpWd5kP4rriGG841E1Z-mqDX5Iovp8bAOAMbmU0Ytm31v6UTG10tb7GbeFEb7mg4EYUhzKh7ia4yp8LKs/s1600/body.jpg&quot; imageanchor=&quot;1&quot; style=&quot;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;27&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyWvoO_uY6UIDHJB2FfvHxWJdmbRMfJvDvy7Zqj1nQ2iPx1z_Tq7mNxDZ8HkBpWd5kP4rriGG841E1Z-mqDX5Iovp8bAOAMbmU0Ytm31v6UTG10tb7GbeFEb7mg4EYUhzKh7ia4yp8LKs/s400/body.jpg&quot; /&gt;&lt;/a&gt;


&lt;br/&gt;
&lt;pre class=&#39;brush:html&#39;&gt;
&lt;div align=&quot;center&quot;&gt;
  &lt;h1&gt;It&#39;s My Ajax Page&lt;/h1&gt;
  &lt;a href=&quot;content1.html&quot; onclick=&quot;makeRequest(&#39;content1.html&#39;,&#39;hw&#39;); return false;&quot;&gt;
            Home 
        &lt;/a&gt; | 
  &lt;a href=&quot;content2.html&quot; onclick=&quot;makeRequest(&#39;content2.html&#39;,&#39;hw&#39;); return false;&quot;&gt;
            Page 2
        &lt;/a&gt; | 
  &lt;a href=&quot;content3.html&quot; onclick=&quot;makeRequest(&#39;content3.html&#39;,&#39;hw&#39;); return false;&quot;&gt;
            Page 3
        &lt;/a&gt; | 
  &lt;a href=&quot;content4.html&quot; onclick=&quot;makeRequest(&#39;content4.html&#39;,&#39;hw&#39;); return false;&quot;&gt;
            Page 4
        &lt;/a&gt;
        
  &lt;div id=&quot;hw&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;

&lt;h4&gt;Make other sub-pages in the same folder like following - &lt;/h4&gt;
&lt;br/&gt;
&lt;h4&gt;content1.html&lt;/h4&gt;
&lt;pre class=&#39;brush:html&#39;&gt;
&lt;!-- content1.html --&gt;
&lt;div style=&quot;width: 770px; text-align: left;&quot;&gt;
&lt;h1&gt;Page 1&lt;/h1&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
 enim ad minimveniam, quis nostrud exercitation ullamco laboris
 nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor 
        in reprehenderit in voluptate velit esse cillum dolore eu
 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
 proident, sunt in culpa qui officia deserunt mollit anim id est
 laborum.&lt;/p&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;br/&gt;
&lt;h4&gt;content2.html&lt;/h4&gt;
&lt;pre class=&#39;brush:html&#39;&gt;
&lt;!-- content2.html --&gt;
&lt;div style=&quot;width: 770px; text-align: left;&quot;&gt;
&lt;h1&gt;Page 2&lt;/h1&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
 enim ad minimveniam, quis nostrud exercitation ullamco laboris
 nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor 
        in reprehenderit in voluptate velit esse cillum dolore eu
 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
 proident, sunt in culpa qui officia deserunt mollit anim id est
 laborum.&lt;/p&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;br/&gt;
&lt;h4&gt;content3.html&lt;/h4&gt;
&lt;pre class=&#39;brush:html&#39;&gt;
&lt;!-- content3.html --&gt;
&lt;div style=&quot;width: 770px; text-align: left;&quot;&gt;
&lt;h1&gt;Page 3&lt;/h1&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
 enim ad minimveniam, quis nostrud exercitation ullamco laboris
 nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor 
        in reprehenderit in voluptate velit esse cillum dolore eu
 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
 proident, sunt in culpa qui officia deserunt mollit anim id est
 laborum.&lt;/p&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;br/&gt;
&lt;h4&gt;content4.html&lt;/h4&gt;
&lt;pre class=&#39;brush:html&#39;&gt;
&lt;!-- content4.html --&gt;
&lt;div style=&quot;width: 770px; text-align: left;&quot;&gt;
&lt;h1&gt;Page 4&lt;/h1&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
 enim ad minimveniam, quis nostrud exercitation ullamco laboris
 nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor 
        in reprehenderit in voluptate velit esse cillum dolore eu
 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
 proident, sunt in culpa qui officia deserunt mollit anim id est
 laborum.&lt;/p&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;p class=&#39;aligned&#39;&gt;
Note: If you are working on you local machine, you have install and enable your local apache server, and you should run the page using localhost. There are so many server application pack out there, most popular for windows - XAMPP, WAMP, for mac MAMP. Use whichever you comfort with.&lt;br/&gt;
Check out the demo from &lt;a href=&#39;http://simonsportfolio.elementfx.com/ajaxexample/&#39; target=&#39;_blank&#39; style=&#39;color: blue;&#39;&gt;here&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
As you can see, by making use of Ajax, you can create a fully functional, Ajax navigation–driven site in a manner of minutes. You include the JavaScript required to process the links into &amp;#60;script&amp;#62; tags in the head, and can then make use of the makerequest() function at any time to send a server-side request to the web server without refreshing the page. You can call the makerequest() function on any event (you are using onclick() here) to load content into the respective object that is passed to the function.
&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/4183938949776211766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/using-ajax-as-navigational-tool-basic.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/4183938949776211766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/4183938949776211766'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/using-ajax-as-navigational-tool-basic.html' title='Using AJAX as Navigational Tool [ Basic Ajax Example ]'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyWvoO_uY6UIDHJB2FfvHxWJdmbRMfJvDvy7Zqj1nQ2iPx1z_Tq7mNxDZ8HkBpWd5kP4rriGG841E1Z-mqDX5Iovp8bAOAMbmU0Ytm31v6UTG10tb7GbeFEb7mg4EYUhzKh7ia4yp8LKs/s72-c/body.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-2130879206762928507</id><published>2012-07-29T18:33:00.000+03:00</published><updated>2012-07-29T22:22:30.603+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><title type='text'>AJAX TUTORIAL : Sending a Request to the Server</title><content type='html'>&lt;p class=&#39;aligned&#39;&gt;
First of all, you should already know how to create XMLHttpRequest object. If you already know how to create it skip this. To make a new XMLHttpRequest object please follow my this blog content - &lt;a href=&#39;http://simonsnotes.blogspot.com/2012/07/creating-ajax-crossbrowser.html&#39; style=&#39;color:#B33400;&#39;&gt;&lt;i&gt;Creating XMLHttpRequest object&lt;/i&gt;&lt;/a&gt; 
&lt;br/&gt;&lt;br/&gt;
Now that you have your shiny, new XMLHttpRequest object ready for use, the natural next
step is to use it to submit a request to the server. This can be done in a number of ways, but the key aspect to remember is that you must validate for a proper response, and you must decide whether to use the GET or POST method to do so. It should be noted that if you are using Ajax to retrieve information from the server, the GET method is likely the way to go. If you are sending information to the server, POST is the best way to handle this. I’ll go into more depth with this later in the book, but for now, note that GET does not serve very well to send information due to its inherent size limitations.
&lt;br/&gt;&amp;emsp;
In order to make a request to the server, you need to confirm a few basic functionality based questions. First off, you need to decide what page (or script) you want to connect to, and then what area to load the page or script into. Consider the following function, which receives as arguments the page (or script) that you want to load and the div (or other object) that you want to load the content into.

&lt;pre class=&#39;brush:javascript&#39;&gt;
function makerequest(serverPage, objID) {

  var obj = document.getElementById(objID);
  xmlhttp.open(&quot;GET&quot;, serverPage);

  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
      obj.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}
&lt;/pre&gt;
&lt;br/&gt;
Basically, the code here is taking in the HTML element ID and server page. It then
attempts to open a connection to the server page using the open() method of the
XMLHttpRequest object. If the readyState property returns a 4 (complete) code and the
status property returns a 200 (OK) code, then you can load the response from the
requested page (or script) into the innerHTML element of the passed-in object after you send the request.
&lt;br/&gt;&amp;emsp;
Basically, what is accomplished here is a means to create a new XMLHttpRequest object
and then use it to fire a script or page and load it into the appropriate element on the page. Now you can begin thinking of new and exciting ways to use this extremely simple concept.
&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/2130879206762928507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/sending-request-to-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/2130879206762928507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/2130879206762928507'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/sending-request-to-server.html' title='AJAX TUTORIAL : Sending a Request to the Server'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-2579115151852659695</id><published>2012-07-29T15:24:00.000+03:00</published><updated>2012-07-29T15:50:33.054+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><title type='text'>Creating AJAX Crossbrowser XMLHttpRequest Object Instance</title><content type='html'>&lt;p style=&#39;text-align: justify;&#39;&gt;
  Although at the time of this writing, Microsoft’s Internet Explorer continues to dominate the browser market, competitors such as Firefox have been making significant headway. Therefore, it is as important as ever to make sure your Ajax applications are crossbrowser compatible. One of the most important aspects of the Ajax functionality is that it can be deployed across browsers rather seamlessly, with only a small amount of work required to make it function across most browsers (the exception being rather old versions of the current browsers). Consider the following code snippet, which instantiates an instance of the XMLHttpRequest object, and works within any browser that supports XMLHttpRequest.
 &lt;/p&gt;
 &lt;pre class=&quot;brush:javascript&quot;&gt;
  
//Create a boolean variable to check for a 
//valid Internet Explorer instance.
 var xmlhttp = false;
 if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
 }
 else
 {// code for IE6, IE5
   xmlhttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
 }  
 &lt;/pre&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
 function promptBrowser(){
  var bName = navigator.appCodeName;
  var bVersion = navigator.appVersion;

  if(window.XMLHttpRequest)
   alert(&#39;Your browser is newer than IE6\nYour are using &#39;+bName+&#39; &#39;+bVersion);
  else
   alert(&#39;Your browser is either IE6 or later\nYour are using &#39;+bName+&#39; &#39;+bVersion);
 }
 &lt;/script&gt;
 &lt;br/&gt;
&lt;p&gt;Click below button to check your browser.&lt;/p&gt;
&lt;button onclick=&#39;promptBrowser();&#39; style=&#39;padding: 10px; font-weight: bold; margin-left:30%;&#39;&gt;CHECK YOUR BROWSER&lt;/button&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/2579115151852659695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/creating-ajax-crossbrowser.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/2579115151852659695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/2579115151852659695'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/creating-ajax-crossbrowser.html' title='Creating AJAX Crossbrowser XMLHttpRequest Object Instance'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-6157635645729356409</id><published>2012-07-29T14:33:00.001+03:00</published><updated>2012-07-29T14:34:50.191+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><title type='text'>The XMLHttpRequest Object</title><content type='html'>&lt;p style=&#39;text-align:justify&#39;&gt;
Ajax is really just a concept used to describe the interaction of the client-side
XMLHttpRequest object with server-based scripts. In order to make a request to the server
through Ajax, an object must be created that can be used for different forms of functionality.
It should be noted that the XMLHttpRequest object is both instantiated and handled a
tad differently across the browser gamut. Of particular note is that Microsoft Internet
Explorer creates the object as an ActiveX control, whereas browsers such as Firefox and
Safari use a basic JavaScript object. This is rather crucial in running cross-browser code
as it is imperative to be able to run Ajax in any type of browser configuration.
&lt;/p&gt;
&lt;p style=&#39;text-align:justify&#39;&gt;
&lt;h4&gt;XMLHttpRequest Methods&lt;/h4&gt;
Once an instance of the XMLHttpRequest object has been created, there are a number of methods available to the user. These methods are expanded upon in further detail in Table below. Depending on how you want to use the object, different methods may become more important than others.
&lt;/p&gt;

&lt;h4&gt;Table: &lt;i style=&#39;font-weight:100;&#39;&gt;XMLHttpRequest Object Methods&lt;/i&gt;&lt;/h4&gt;
&lt;table style=&#39;border-bottom: 2px solid #444444;&#39;&gt;
 &lt;tr&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444; width: 180px;&#39;&gt;Method&lt;/th&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444;&#39;&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;abort()&lt;/td&gt;
  &lt;td&gt;Cancels the current request&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;getAllResponseHeaders()&lt;/td&gt;
  &lt;td&gt;Returns all HTTP headers as a String type variable&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;getResponseHeader()&lt;/td&gt;
  &lt;td&gt;Returns the value of the HTTP header specified in the method&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;open()&lt;/td&gt;
  &lt;td&gt;Specifies the different attributes necessary to make a connection to
the server; allows you to make selections such as GET or POST (more
on that later), whether to connect asynchronously, and which URL
to connect to&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;setRequestHeader()&lt;/td&gt;
  &lt;td&gt;Adds a label/value pair to the header when sent&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;500 Internal Server Error&lt;/td&gt;
  &lt;td&gt;This code will be returned if the server that is being contacted has a
problem.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;send()&lt;/td&gt;
  &lt;td&gt;Sends the current request&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;
&lt;br/&gt;
&lt;h4&gt;XMLHttpRequest Properties&lt;/h4&gt;
&lt;p style=&#39;text-align: justify;&#39;&gt;
 Of course, any object has a complete set of properties that can be used and manipulated
in order for it work to its fullest. A complete list of the XMLHttpRequest object properties
is presented in Table below. It is important to take note of these properties you will be
making use of them as you move into the more advanced functionality of the object.
&lt;/p&gt;
&lt;h4&gt;Table: &lt;i style=&#39;font-weight:100;&#39;&gt;XMLHttpRequest Object Properties&lt;/i&gt;&lt;/h4&gt;
&lt;table style=&#39;border-bottom: 2px solid #444444;&#39;&gt;
 &lt;tr&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444; width: 180px;&#39;&gt;Property&lt;/th&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444;&#39;&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;onreadystatechange&lt;/td&gt;
  &lt;td&gt;Cancels the current request&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;readyState&lt;/td&gt;
  &lt;td&gt;Contains the current state of the object (0: uninitialized, 1: loading,
2: loaded, 3: interactive, 4: complete)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;responseText&lt;/td&gt;
  &lt;td&gt;Returns the response in string format&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;responseXML&lt;/td&gt;
  &lt;td&gt;Returns the response in proper XML format&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;status&lt;/td&gt;
  &lt;td&gt;Returns the status of the request in numerical format (regular page
errors are returned, such as the number 404, which refers to a not
found error)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;statusText&lt;/td&gt;
  &lt;td&gt;Returns the status of the request, but in string format (e.g., a 404 error
would return the string Not Found)&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/6157635645729356409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/xmlhttperequest-object.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/6157635645729356409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/6157635645729356409'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/xmlhttperequest-object.html' title='The XMLHttpRequest Object'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-2471315816432301744</id><published>2012-07-29T05:24:00.000+03:00</published><updated>2012-07-29T14:20:36.731+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><title type='text'>AJAX HTTP Request and Response</title><content type='html'>&lt;p style=&quot;text-align: justify;&quot;&gt;
In order to understand exactly how Ajax concepts are put together, it is important to
know how a web site processes a request and receives a response from a web server. The
current standard that browsers use to acquire information from a web server is the HTTP (HyperText Transfer Protocol) method (currently at version HTTP/1.1). This is the means a web browser uses to send out a request from a web site and then receive a response from the web server that is currently in charge of returning the response.
&lt;/br&gt;
HTTP requests work somewhat like e-mail. That is to say that when a request is sent,
certain headers are passed along that allow the web server to know exactly what it is to be serving and how to handle the request. While most headers are optional, there is one header that is absolutely required (provided you want more than just the default page on the server): the host header. This header is crucial in that it lets the server know what to serve up.
&lt;/br&gt;
Once a request has been received, the server then decides what response to return.
There are many different response codes. Table below has a listing of some of the most
common ones.
&lt;/p&gt;
&lt;h4&gt;Table: Common HTTP Response Codes&lt;/h4&gt;
&lt;table style=&#39;border-bottom: 2px solid #444444;&#39;&gt;
 &lt;tr&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444; width: 180px;&#39;&gt;Code&lt;/th&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444;&#39;&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;200 OK&lt;/td&gt;
  &lt;td&gt;This response code is returned if the document or file in question is
found and served correctly.&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;304 Not Modified&lt;/td&gt;
  &lt;td&gt;This response code is returned if a browser has indicated that it has
a local, cached copy, and the server’s copy has not changed from
this cached copy.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;401 Unauthorized&lt;/td&gt;
  &lt;td&gt;This response code is generated if the request in question requires
authorization to access the requested document.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;403 Forbidden&lt;/td&gt;
  &lt;td&gt;This response code is returned if the requested document does not
have proper permissions to be accessed by the requestor.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;404 Not Found&lt;/td&gt;
  &lt;td&gt;This response code is sent back if the file that is attempting to be
accessed could not be found (e.g., if it doesn’t exist).&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;500 Internal Server Error&lt;/td&gt;
  &lt;td&gt;This code will be returned if the server that is being contacted has a
problem.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;503 Service Unavailable&lt;/td&gt;
  &lt;td&gt;This response code is generated if the server is too overwhelmed to
handle the request.&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;p style=&#39;text-align: justify;&#39;&gt;
It should be noted that there are various forms of request methods available. A few
of them, like GET and POST, will probably sound quite familiar. Table below lists the available request methods (although generally only the GET and POST methods are used).
&lt;/p&gt;

&lt;h4&gt;Table: &lt;i&gt;HTTP Request Methods&lt;/i&gt;&lt;/h4&gt;
&lt;table style=&#39;border-bottom: 2px solid #444444;&#39;&gt;
 &lt;tr&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444; width: 180px;&#39;&gt;Method&lt;/th&gt;
  &lt;th style=&#39;border-bottom: 2px solid #444444; border-top: 2px solid #444444;&#39;&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;GET&lt;/td&gt;
  &lt;td&gt;The most common means of sending a request; simply requests a specific
resource from the server&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;HEAD&lt;/td&gt;
  &lt;td&gt;Similar to a GET request, except that the response will come back without the
response body; useful for retrieving headers&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;POST&lt;/td&gt;
  &lt;td&gt;Allows a request to send along user-submitted data (ideal for web-based forms)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;PUT&lt;/td&gt;
  &lt;td&gt;Transfers a version of the file request in question&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;DELETE&lt;/td&gt;
  &lt;td&gt;Sends a request to remove the specified document&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;TRACE&lt;/td&gt;
  &lt;td&gt;Sends back a copy of the request in order to monitor its progress&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;OPTIONS&lt;/td&gt;
  &lt;td&gt;Returns a full list of available methods; useful for checking on what methods a
server supports&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;CONNECT&lt;/td&gt;
  &lt;td&gt;A proxy-based request used for SSL tunneling&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;
&lt;p style=&#39;text-align: justify;&#39;&gt;
Now that you have a basic understanding of how a request is sent from a browser
to a server and then has a response sent back, it will be simpler to understand how the
XMLHttpRequest object works. It is actually quite similar, but operates in the background
without the prerequisite page refresh.
&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/2471315816432301744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/ajax-http-request-and-response.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/2471315816432301744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/2471315816432301744'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/ajax-http-request-and-response.html' title='AJAX HTTP Request and Response'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1797584766668995213.post-7294207458846648439</id><published>2012-07-29T03:39:00.000+03:00</published><updated>2012-07-29T04:18:39.859+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AJAX"/><title type='text'>REQUIREMENTS FOR AJAX</title><content type='html'>&lt;p style=&#39;text-align:justify&#39;&gt;
Before starting I would like to mention few words about the post, this content was collected form the book named &quot;&lt;i&gt;&lt;span style=&#39;font-weight:900&#39;&gt;Beginning Ajax with PHP&lt;/span&gt; - From Novice to Professional&lt;/i&gt;&quot;. Basically according to the blog title, this is my notebook. I am not a professional developer, I am student and I am just sharing what I am learning with my fellow learners. If somehow this content is a cause of violation please ping, I will be glad to know if there is any problem.  
&lt;/p&gt;

&lt;h4&gt;
 AJAX REQUIREMENT
&lt;/h4&gt;
&lt;p style=&#39;text-align:justify&#39;&gt;
 Since Ajax is based upon JavaScript technology, it goes without saying that JavaScript
must be enabled in the user’s browser in order for it to work. That being said, most people
do allow their browsers to use JavaScript, and it is not really that much of a security
issue to have it in place. It must be noted, however, that the user does have the ability to effectively “disable” Ajax, so it is important to make sure, when programming an Ajax
application, that other means are available to handle maneuvering through the web site;
or alternatively, that the user of the web site is kept properly informed of what is necessary
to operate the application.
&lt;br/&gt;&amp;emsp;
Ajax is a fairly widely supported concept across browsers, and can be invoked on
Firefox (all available versions), Internet Explorer (4.0 and higher), Apple Safari (1.2 and
higher), Konqueror, Netscape (7.1 and higher), and Opera (7.6 and higher). Therefore,
most browsers across the widely used gamut have a means for handling Ajax and its
respective technologies.
&lt;br/&gt;&amp;emsp;

At this point, the only real requirement for making use of Ajax in an efficient and productive
manner is the creativity of going against what the standard has been telling us for
years, and creating something truly revolutionary and functional.
&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://simonsnotes.blogspot.com/feeds/7294207458846648439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/requirements-for-ajax.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/7294207458846648439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1797584766668995213/posts/default/7294207458846648439'/><link rel='alternate' type='text/html' href='http://simonsnotes.blogspot.com/2012/07/requirements-for-ajax.html' title='REQUIREMENTS FOR AJAX'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02235608528199130998</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>