FSD Module-5 Notes
FSD Module-5 Notes
● Ajax Solution,
● Java Script,
● XHTMLHttpRequest and Response,
● HTML, CSS,
● JSON, iFrames,
● Settings of Java Script in Django,
● jQuery and Basic AJAX,
● jQuery AJAX Facilities,
● Using jQuery UI Autocomplete in Django
Course Objectives:
Design and implement Django apps containing dynamic pages with SQL databases.
Perform jQuery based AJAX integration to Django Apps to build responsive full stack web applications,
⮚ Ajax is a way of using client-side technologies to talk with a server and perform
partial page updates.
XMLHttpRequest- Methods:
Properties :
1. XMLHttpRequest.onreadystatechange, & XMLHttpRequest.readyState
• A bare-bones XMLHttpRequest object can be expected to have the following
properties:
– XMLHttpRequest.onreadystatechange - which is called without argument each
time the ready state of XMLHttpRequest changes.
• An XMLHttpRequest object can have five ready states:
– Uninitialized, meaning that open() has not been called.
– Open, meaning that open() has been called but send() has not.
– Sent, meaning that send() has been called, and waiting
– Receiving, meaning that the response is being downloaded
Features of XML :
o XML focuses on data rather than how it looks
o Easy and efficient data sharing
o Compatibility with other markup language HTML
o Supports platform transition
JavaScript/Ajax Libraries :
• https://code.jquery.com/jquery.min.js
• jquery.min.js – Js Library
• JavaScript libraries offer several advantages.
• They can reduce chores and boilerplate code, significantly lessening the pain of
JavaScript, and provide a more uniform interface.
• They can also provide (for instance) ready-made widgets; a jQuery
• And on a broad scale, they can let the JavaScript you write be higher-level and a little
more Pythonic.
JQuery :
• jQuery is a lightweight, "write less, do more", JavaScript library.
• The purpose of jQuery is to make it much easier to use JavaScript on your website.
• jQuery takes a lot of common tasks that require many lines of JavaScript code to
accomplish, and wraps them into methods that you can call with a single line of code.
• jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX
calls and DOM manipulation.
• The jQuery library contains the following features:
• HTML/DOM manipulation
• CSS manipulation
• HTML event methods
• Effects and animations
• AJAX
• Utilities
Jquery Selectors :
Ajax workflow :
1. user clicks, invoking an event handler
2. handler's code creates an XMLHttpRequest object
$.ajax() :
• The most foundational and low-level workhorse in jQuery is $.ajax().
• It takes the arguments as shown in the following Sample invocation.
• Default values can be set with $.ajaxSetup(), as discussed below:
• Closures
• Closures represent a key concept in core JavaScript, along with other things
such as functions, objects, and prototypes.
• Closures are part of the conceptual landscape and they are the basis on how to
effectively create an object with private fields.
• example : using a closure to create an object with private variables, which
creates an object that stores an integer value, has a getter and setter, but in Java
fashion ensures that the field can only have an integer value.
parameters of $.ajax() :
• dataFilter
– This is a reference to a function that will be passed two arguments:
• the raw response given by an XMLHttpRequest, and
• a type (xml, json, script, or html).
– This offers an important security hook.
– One of the cardinal rules of security on both the client-side and server-side is
to treat all input as guilty until proven innocent of being malicious.
• Even though it is a "double work" chore, user input should both be validated at the
client-side and the server-side:
– client-side as a courtesy to the user to improve the user experience and not as
trustworthy security,
– and on the server side as a security measure against malicious data even if it
is malformed malicious data that no normal web browser would send.
• jQuery does not automatically include functionality to test whether something served
up as JSON is malicious, and methods like .getJSON() trustingly execute what might
contain malicious JavaScript
• dataType
– This is something you should specify, and provide a default specified value via
$.ajaxSetup(), for example:
– $.ajaxSetup({dataType: "text"});
– The possible values are html, json, jsonp, script, text, and xml.
– If you do not specify a value, jQuery will use an unsecure "intelligent
guessing" that may cause security issues.
–
• This much of the code is run once and creates the beginning of the containing
paragraph, sets a strong tag, and creates the entry for no department selected.
• Then we loop through the list of departments, creating an option that has a value of
"department." followed by the id of the entity provided as a department.