Lecture 3 Jquery & JSON
Lecture 3 Jquery & JSON
1. Introduction to jQuery
2. Incorporate jQuery
3. jQuery makes writing JS easier
4. jQuery Syntax
5. jQuery Selector
6. jQuery Events
7. jQuery Ajax
8. jQuery UI and its advantages
Lecture Outline
9. Introduction to JSON
10. JSON structure
11. JSON Array
12. JSON data sending from client/server
Lecture Objective
<h1></h1> <h1></h1>
<input type=“button” value=“click”/> <input type=“button” value=“click” onclick=“f1()”/>
<script> <script>
$(‘button’).click(function(){ function f1(){
$(‘h1’).html(‘Button Clicked!’); document.getElementsByTagName(h1).inner
}); HTML = “Button Clicked!”;
</script> });
</script>
jQuery Syntax Vanilla JS Syntax
Incorporate jQuery
There are several ways to start using jQuery on your web site. You can:
The jQuery syntax is tailor-made for selecting HTML elements and performing
some action on the element(s).
Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".
jQuery Selector
jQuery selectors allow you to select and manipulate HTML element(s).jQuery
selectors are used to "find" (or select) HTML elements based on their name, id,
classes, types, attributes, values of attributes and much more. All selectors in
jQuery start with the dollar sign and parentheses: $().
$("button").click(function(){
$.ajax({
url: “abc.txt",
method: ‘GET’,
data: {},
success: function(result){
$("#div1").html(result);
},
error: function(err){ $("#div1").html(result); }
});
});
jQuery UI
jQuery UI is a curated set of user interface interactions, effects,
widgets, and themes built on top of the jQuery JavaScript Library.
Whether you're building highly interactive web applications, or you
just need to add a date picker to a form control, jQuery UI is the
perfect choice.
Accordion
Autocomplete
Datepicker
Tabs etc.
Introduction to JSON
When exchanging data between a browser and a server, the data can
only be text. JSON is text, and we can convert any JavaScript object
into JSON, and send JSON to the server.
JSON Structure
var data = {
‘name’ : ‘XYZ’,
‘age’ : 23
}
var cars = [
{ "name":"Ford", "models":[ "Fiesta", "Focus", "Mustang" ] },
{ "name":"BMW", "models":[ "320", "X3", "X5" ] },
{ "name":"Fiat", "models":[ "500", "Panda" ] }
]
JSON Data Sending to Server
1. https://www.w3schools.com/jquery/default.asp
2. https://api.jquery.com/
3. https://jqueryui.com/
4. https://www.w3schools.com/js/js_json_intro.asp
Thank You!