What Is Jquery ?: Document - Getelementbyid ("Txt1") .Value "Hello"
What Is Jquery ?: Document - Getelementbyid ("Txt1") .Value "Hello"
What Is Jquery ?: Document - Getelementbyid ("Txt1") .Value "Hello"
Jquery is a reusable javascript library which simplifies javascript coding. So rather than writing
length javascript code as below.
If you want to kick start with Jquery start with the below video which is created
by www.questpond.com
So if a user is from India, the Indian CDN server will serve request for Indian users. This leads to
faster delivery of data.
If you want to reference google CDN Jquery files you can use the below script.
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
If you want to use Microsoft CDN you can use the below javascript.
src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">
</script>
First reference the CDN jquery. In the below code you can see we have reference Microsoft CDN
jquery file.
Now if Microsoft CDN is down then the Jquery value will be “undefined”. So you can see in the
below code we are checking if the Jquery is having “undefined” value then do a document write
and reference your local Jquery files.
So you can use the “noConflict” method and release the jquery “$” sign as shown in the below
code.
You can also create your own jquery shortcut as shown below.
Select all
Below is a simple code snippet which selects all paragraph tags and hides them.
Select by ID
So we would like to execute the Jquery code which sets the textbox value only when all
the HTML objects are loaded in DOM. So you can replace the code of setting text box value to
something as shown below.
Here is a nice detail article with a video which explains Jquery Ready event in a more detail
manner http://www.dotnetinterviewquestions.in/article_jquery-interview-questions:-when-do-
we-need-documentreadyevent-_230.html
Below is one more example where we have attached the a function to a mouse enter event of a
paragraph.
What is JSON?
JSON (JavaScript object notation) helps us to present and exchange data in a self-descriptive,
independent and light way. This data can then be easily consumed and transformed in to
javascript objects.
Below is a simple example of JSON format looks. You can understand from the format how
lightweight and easy the format looks.
Figure :- JSON
The biggest advantage of JSON format is it can be evaluated to a javascript object. For instance
you can see in the below code snippet we have a JSON format data which has
“name”,”street”,”age” and “phone”. Now this data can be consumed as shown in the code snippet
below, evaluated to a javascript object and invoked as anobject property.
You can see how we have called the “name” property using an object “JSONObject.name”.
var JSONObject= {
"name":"John Johnson",
"street":"Oslo West 555",
"age":33,
"phone":"555 1234567"};
alert(JSONObject.name);
</script>
If you want your MVC to emit out JSON data you can return “JsonResult” as shown below. If you
call the below action it will emit out Customer objects in Json format.
To make a call to the above MVC action using Jquery we need to use “getJSON” method. Below
is the simple code for the same. It has three parameters:-
1. The first parameter is the URL which emits out JSON. For instance in the below code the URL is
“/Employee/getEmployee”.
2. The next parameter helps us to pass data to the resource which emits out JSON currently it’s the
MVC action. Currently we are only doing a get so the second parameter is NULL for now.
3. The last parameter is the call back function which will be invoked once the MVC action returns
data. You can see how the “getData” function just displays the “empcode” property. Because the
output is in JSON it automatically converts the JSON data to javascript object.
Hide Copy Code
$.getJSON("/Employee/getEmployee", null, getData);
function getData(data)
{
alert(data.empcode);
}
$.post("/Send/Request", // URL
mydata , // Data to be sent
function(data,status){alert(data + " " + status);}); // Call back function
The above posted JSON string is received at the server side “request.inputstream” , below is a
simple sample code for the same.
“JsonString” is the string which has the JSON value and by using “Deserialize” we are converting
the string to a c# object. Now this object which we receive is a collection of “key” and “value” pair
which can be browsed and accessed in c#.
What is Angular JS ?
AngularJS is JavaScript framework to create SPA applications. It simplifies complex javascript
DOM manipulation code by providing declarative tags. This provides a clean separation between
DOM manipulation logic and the HTML view.
For example below is a simple Angular code which helps us to display textbox data in the DIV tag
when the user types in the textbox.
Below is a simple angular code which has all the three things: -
For example below is a simple CSS which has two styles “style1” and “style2”. If you notice the
below CSS the background color is duplicated. If we ever want to change this we have to change
in multiple places.
But if use “LESS.JS” we can create a variable which has color stored and set the CSS property
using the variable. If we ever want to change the color we just need to change the variable value.
Below is a simple LESS enabled CSS where we have created a variable “mybackgroundcolor”
which is set at the top and that variable is then used to set the background color property in the
CSS. This makes our CSS dynamic and easy to maintain.
Before running the above code ensure that you have link to less.js file at the top. You can get less
JS file from lesscss.org.
You can also watch this video which is created by www.questpond.com which demonstrates LESS
in a step by step manner.
In both the styles we have set two properties with the same value. For both the properties we
have created two variables. But what if we have 10 such properties then you will end up with 10
such variables.
So rather than defining lot of hanging variables we can define a mixin. In the below code you can
see we have defined a mixin by the name “common”. We have applied that mixin to both styles
in one go. So we can conclude that mixin is structure for common values and common
properties.
License