LOG

Tuesday, December 15, 2009

REST

Web is REST platform for an application. What ever Application you make for World Wide Web basically follows the rules of REST no matter what, so to make better web apps the application architecture should be made with the principals of REST in mind. What is REST!? 

RESTful application has this architecture,
1) Client - Server (front end - back end)
Client-server architecture is used to retrieve information for end user. Client asks for certain information and server responds with the desired information or responds with error information.     

2) Request - Response
       Client requests for information and server responds with appropriate information corresponding to the client's request.

3) URI/URL
Every information pool in the system is identified with a unique Uniform Resource Identifier. 

4) Stateless
There is no relation between the current request and the previous request(s). In another words state is not maintained between client's requests.


Thursday, September 10, 2009

Video tutorials - Ajax

This is kinda transcript of Ajax tutorials I made on youtube.

What is Ajax?
Ajax stands for Asynchronous Javascript and XML, Almost every website uses this technique. This is not a programming language or something but merely a Javascript technique to fetch data from server (like requesting a webpage) without leaving the current page. You get the data from the server in a variable, it can be HTML which you can include directly into some part of the page using Javascript DOM or it can be XML or JSON, atleast these are what the server usually sends back while you have the choice to chose which ever format you like, not confined to formates mentioned here.

Why Ajax?
Ajax gives a real time feel to your web page. And you can make rich web applications using Ajax. Alot of load is transfered from the server as it can only be used to fetch data and other processing load is on the client. Well that also wouldn't be a wise move to stuff up your client's RAM or do alot of processing there. We will look more into it afterwards. In a nutshell Ajax request and a simple request via click redirect is Ajax give you capability to request more than one pages while simple request takes you to that page.

Ajax stuff!
In javascript Ajax is done using XMLHTTP request object. Which has a different name in IE.

gecko browsers call it = XMLHTTPRequest
IE call it = ActiveXObject("Microsoft.XMLHTTP");
So now lets move on and see how can we use this object.

Lets initialize our variable 'xmlhttp' with these objects. Notice how we acheive this so we can do ajax on both gecko browsers and IE.

//using try catch statements to get the Ajax object
var xmlhttp= null; //intializing our variable with null intially.
try {
//try this block
xmlhttp= new XMLHTTPRequest; //This code will run fine in Gecko browsers but will generate an error in IE so we will catch that error in "catch" block below
} catch(e) {
try {
//so the above block generated error in IE we caught the error now error handling starts
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); //This will run in IE without generating errors.
}catch(e) {
//This block will only execute if client's browser doesn't support Ajax at all.
alert("Browser doesn't support AJAX");
}
}

So till here we will have a valid Ajax object or the browser doesn't support Ajax at all. So in the next part of this tutorial we will see how we can use this object to request pages and send content with it use GET / POST request. It your choice to use which HTTP request method, you cannot use both on one object, below we will see how can we use each.

GET request!
GET request is a usuall HTTP request method like when you click on a link that would probably be a GET request and Forms usually use POST request. So far we have seen how can we get a valid XMLHTTP request object. Now we will use that object and use GET HTTP request method.

xmlhttp.open("GET", "file1.php?name=value", true); //{1}
xmlhttp.onreadystatechange = function () { //{2}
if(this.readyState== 4) { //{3}
if(this.status== 200) { //{4}
// you got a response from the server without any errors on the server
alert(this.responseText); // {5}
}
}
}
xmlhttp.send(null); // {6}

Comments.
  1. xmlhttp.open([HttpRequest Method], [webpage], [Async Response]), This method intializes the request. [HttpRequest Method] is what method you want the request to have, [webpage] is the page on server where you want the content from, it can be URL or relative path, [Async Response] if this 'true' then it means that javascript won't wait untill the response is fully loaded, Code will be executed if there is any code in line to be run. while if it false, Javascript will pause until it gets the response from the server.
  2. [Post not done yet]...

Video tutorials - JSON in Ajax(PHP and JavaScript)

Json library - http://www.json.org/json2.js .

Include above mentioned library before coding json code any further. Even though you can get same kind of functionality without using this library with pure javascript .

[obj].toSource() === JSON.stringify([obj]);
eval([obj].toSource()) === [obj];
// [obj] == any javascript object.

Remember don't include any methods/functions in your javasscript object if you are gonna pass its JSON around different languages. [obj].toSource() will also enclose the object's source (JSON) with parranthesis '([obj_source])', which is a necessity for javascript's eval() method. While this apporch may cause problem when you deal with JSON in different languages, like un quoted 'names' and stuff. so better off use the standard JSON library provided at the top.

PHP 5.x and above have built in support for encoding and decoding JSON, for previous versions download a JSON package from PHP pear or use a JSON library which is included in Major PHP frameworks.


Wednesday, August 12, 2009

Buyakasha

Today was really bad day for me. I now crashed my brothers PC and my old PC is caseless it gives shocks and stuff. it works but the problem with it is it can't stay turned on fucker freezes everytime there is something heavy going on. What should i do with the old one, wtf i can trash it, it costed money and you don't make much money here so now what i am going to do is sell it part by part :).

Friday, March 6, 2009

I love my PC!

Today i found my pc has been crashed due to a viruse (HEUR). Last night I downloaded a crack for my evaluated version of MIRC (i dont know if anyone uses it anymore), but that turned out to be a very bad virus. I had my kaspersky antivirus turned off at that time, but when I clicked the exe of the crack I wondered I should check it if its a virus or not but it was too late.. My whole computer was inffected by it till then wasnt it too fast? I quickly scanned my whole computer with kaspersky and went to sleep next day i found every exe file on my computer to be inffected! I tried to neutralize all of them but during this process I think some of my system files also got removed and my pc crashed and real hard. Both my hard drives are corrupt now. I tried formating them on a different computer i tried to install WinXP and Win98 but no luck. Now am really tired so am going to sleep bu bye.