Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Thursday, January 11, 2018

Ajax Quick Tutorial


AJAX stands for Asynchronous JavaScript and XML. AJAX is not a programming language but a technique for creating interactive web applications. It sends and receives data from client browser to server(independent of server technology).

Significance

  • Though XML is the common format, Ajax supports other types like plain text, Json
  • It allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.


Limitations

  • AJAX has browser incompatibility 
  • For security reasons, modern browsers do not allow access across domains data


Workflow

  • Trigger (on page load, onclick, onchange, etc,.)
  • create XMLHttpRequest object in JavaScript
  • send a request to a web server
  • receive the response
  • process the response in JavaScript


3 Way to use Ajax

Direct Method

function loadDoc() {
  var xhttp = new XMLHttpRequest(); //create XMLHttpRequest object in JavaScript
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) //checking the status and read the data
{document.getElementById("result").innerHTML = this.responseText;}
  };
  xhttp.open("GET", "feed.xml", true); // get or post
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//to set header for content type or cookies
  xhttp.send("m=1&type=summary");//for get parameters can be passed
  xhttp.send();
}

-----------
Callback Method
onclick="loadDoc('ajax_info.txt', myFunction)"

function loadDoc(url, cFunction) {
  var xhttp;
  xhttp=new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {cFunction(this);}
  };
  xhttp.open("GET", url, true);
  xhttp.send();
}
function myFunction(xhttp) {
  document.getElementById("result").innerHTML = xhttp.responseText;
}

JQuery Method
add Jquery lib http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js
<button id="readFile">Read File</button>
$(document).ready(function() {
    $("#readFile").click(function() {
        $.ajax({
            url : "http://macrolayer.blogspot.com/2016/03/waterways.html?m=1",
            dataType: "text",
            success : function (data) {
                alert(data.length);
                alert(data);
            }
        });
    });
});



MethodDescription
new XMLHttpRequest()Creates a new XMLHttpRequest object
abort()Cancels the current request
getAllResponseHeaders()Returns header information
getResponseHeader()Returns specific header information
open(method,url,async,user,psw)"Specifies the request
method: the request type GET or POST
url: the file location
async: true (asynchronous) or false (synchronous)
user: optional user name
psw: optional password"
send(optional string)Sends the request to the server. parameter is used for POST requests.
setRequestHeader()set the header content to be sent


PropertyDescription
onreadystatechangeDefines a function to be called when the readyState property changes
readyState"Holds the status of the XMLHttpRequest.
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready"
responseTextReturns the response data as a string
responseXMLReturns the response data as XML data
status"Returns the status-number of a request 200: ""OK""
403: ""Forbidden""
404: ""Not Found"""
statusTextReturns the status-text (e.g. "OK" or "Not Found")




Thursday, September 7, 2017

Decoding bai file type

This post is all about decoding bai file type. so that any application can be developed convert bai file type to csv or any. csv file is nothing but comma separated values, a simple file format used to store tabular data like spreadsheets. Prior to that, what is bai file type? bai is a file type (.bai extension) used to balance report in banking industry. Technically .bai is just a text file with respective delimiters called codes. Though comma is the column separator, the .bai files are typically formatted in such a way to represent other information using the prefix numeric code with every newline.

The first two digits of each line is the standard code for each line type to tell the system what type of line it is.
------------------------------------------------
01,,,,,,,,
02,,,,1230530,,,
03,80457080,,,,,,
16,475,3000,,1230530,,,456,
88,,
16,475,30000,,1230530,,,789,
98,,,
99,20000,,2
------------------------------------------------
Interpretation
01 File Header Begins File
02 Group Header Begins Group
03 Account Identifier Begins Account
16 Transaction Detail (Optional) Within Account
88 continuation of details
49 Account Trailer Ends Account
98 Group Trailer Ends Group
99 File Trailer Ends File

01
File Header
The file header marks the beginning of a file. It identifies the sender and receiver of the transmission, and it describes the structure of the file.
02
Group Header
The group header identifies a group of accounts that are from the same originator and includes the same as-of-date and as-of-time.
03
Account Identifier and Summary/Status
This record identifies the account number and reports activity summary and account status information. Summary information may be accompanied by an item count and funds availability distribution.
16
Transaction Detail
This record is used for transmission of detail transaction information. Transaction detail may include two reference numbers and a free-form alphanumeric text.
88
Continuation
A Continuation record is used when data exceed the maximum physical record length, or whenever it is desirable to continue data into an additional record. It may follow any record type, including another “continuation” (88) record.
49
Account Trailer
The Account Trailer record provides account control
totals
98
Group Trailer
This record provides group control totals.
99
File Trailer
This record provides file control totals.


File Header
It contains sender, receiver alphanumeric identifiers, File created date in YYMMDD format, File created time, file identification id, number of characters, block size, version number.
Group Header
It contains receiver identifier, originator identifier, status, date, time, currency code.
Account Header
It contains customer account number, currency code, type code, amount, item count, fund type
Transaction Header
It contains Transaction type code, Amount, fund type, bank reference number, customer reference number, Text. Among transaction type code 010 to 099 are reporting purpose. 100 to 399 type codes indicate Credit transaction. 400 to 760 indicate debit transaction.

A bai file should starts with 01 & ends with 99 code. It can have multiple groups starts with 02 & ends with 98 codes. Account details should be inside the group header. 16 indicates all type of Transaction details when the information is large than the continuations will be present with 88 code in next line.


Thursday, April 24, 2014

How to generate automatic emails

Automatic emails can be defined as the emails which are sent out without human action. Automated emails help not only to avoid repeated tasks and also ensure the punctuality in email transfer. I can classify it in two types, predefined and dynamic based on nature of email body content.

Saturday, July 27, 2013

Google UiApp Tutorial

The Google has a wonderful web server scripting application called Apps script. which is not only used for scripting for google products but also can be used to develop stand alone webpages with few limitations. This stand alone web interface is supported by UiApp class. This tutorial will explain about UiApp and its basic controls with a live example script


// Below script contains two functions. one is main function called doGet, which runs by default, other one is user defined function sendback().

//doGet function starts
function doGet() {
//initialize UiApp class
var app = UiApp.createApplication();


//limited HTML
//create HTML using HTML tages and set id or style. note that Anchor tag will not work in this class
var myHTML =  app.createHTML("<center><b>Test Script</b></center>").setStyleAttribute("color", "green").setId('Result');
//add it to UiApp class
app.add(myHTML);

//textArea in UiApp
//create textarea control using textarea class and set id or name, which will help to read and write data
var textAreaA = app.createTextArea().setId('TextArea1').setName('textAreaA');
//you  can design the textarea by calling its id
app.getElementById('TextArea1').setHeight('100').setWidth('450');
//finally add it to UiApp class
app.add(textAreaA);

//textbox in UiApp is more similar like text Area
var textBoxA = app.createTextBox().setId('TextBox1').setName('textBoxA');
app.getElementById('TextBox1').setWidth('300');
app.add(textBoxA);

//Button in UiApp
//Create button with any name
var addButton = app.createButton("Submit").setEnabled(true);
//assign the any user define function and arguments(textAreaA)
var handler = app.createServerClickHandler('sendback').addCallbackElement(textAreaA);
//assign above function to onclick event
addButton.addClickHandler(handler);
//finally add it to UAiApp Class
app.add(addButton);


//label in UiApp
//create label and resize the alignment as well
var labelA = app.createLabel("Developed by macrolayer.blogspot.com").setPixelSize(900,80).setHorizontalAlignment(UiApp.HorizontalAlignment.RIGHT);
//Finally add it to UiApp
app.add(labelA);

//anchor in UiApp
//As I said early, Html doesnot support Anchor tag, this anchor class will help to do so. create and add it to UiApp
var anchor1 = app.createAnchor("View my blog  |", "http://macrolayer.blogspot.com");
app.add(anchor1);



//you can add those classes with good allignment using VerticalPanel or HorizontalPanel
//finally close the function by returning the UiApp class
  return app;
}

//doGet function will execute as userinterface and sendback function will be called once the function is called.(in our example "onclick")

//since we passed argument for this function, the function should have argument e
function sendback(e) {
//get the existing UiApp
  var app = UiApp.getActiveApplication();
//get textAreaA value from parameter e
  var line=e.parameter.textAreaA;


//write your code for other execution using the input value 'line'



//response by new control
//create and add new textArea class and write the output using settext class
var textAreaB= app.createTextArea().setId('TextAreaB').setName('textAreaB').setHeight('100').setWidth('450');;  
app.getElementById('TextAreaB').setText(line);
app.add(textAreaB);
 
//response by existing control
//call the existing control and write the output
 app.getElementById('TextArea1').setText("Your input is " + line);


//finally return the app to display the results
return app;
}




Reference:https://developers.google.com/apps-script/reference/ui/ui-app

Sunday, June 30, 2013

Anchor tag tutorial

Anchor tag is a traditional tag used from the initial stage of HTML to give the navigation option to the user. It allows user to jump a page from and to. This page will describe its attributes and their significance.

Attribute Value Description
hrefabsolute URLdifferent domain, which start with http protocol
href="http://www.differentsite.com/test.asp"
relative URLurl link on same domain, which doesnot need to start with http protocol
href="homepage.html"
href=+"/homepage.html"
example: href="http://www.example.com/2013/test/homepage.html"

href="/homepage.html"
href=+"/homepage.html"
example: href="http://www.example.com/homepage.html"

href="//homepage.org"
href="http:"+"//homepage.org"
example: href="http://homepage.org"

href="./homepage.html"
href=+"/homepage.html"
example: href="http://www.example.com/2013/test/homepage.html"

href="../homepage.html"
href=+"/homepage.html"
example: href="http://www.example.com/2013/homepage.html"
anchor URLhref="#top"
href=+"#top"
example:href="http://www.example.com#top"
mailto protocolhref="mailto:user@example.com? subject=MessageTitle& body=Message Content"
target _blankOpens the linked document in a new window or tab
_self(default)Opens the linked document in the same frame as it was clicked
_parentOpens the linked document in the parent frame
_topOpens the linked document in the full body of the window
framenameOpens the linked document in a named frame
charset char_encoding Not supported in HTML5. Specifies the character-set of a linked document
coords (supported in Firefox and Opera only) x1,y1,x2,y2If the shape attribute is set to "rect", it specifies the coordinates of the top-left corner and the bottom-right corner of the rectangle
x,y,radiusIf the shape attribute is set to "circle", it specifies the coordinates of the circle center and the radius
x1,y1,x2,y2,..,xn,ynIf the shape attribute is set to "poly", it specifies the coordinates of the edges of the polygon. If the first and last coordinate pairs are not the same, the browser must add the last coordinate pair to close the polygon
hreflang language_code A two-letter language code that specifies the language of the linked document. To view all available language codes, go to w3schools Language code reference.
media media_query Specifies what media/device the linked document is optimized for. more
name section_name Not supported in HTML5. Specifies the name of an anchor
rel alternateLinks to an alternate version of the document (i.e. print page, translated or mirror)
authorLinks to the author of the document
bookmarkPermanent URL used for bookmarking
helpLinks to a help document
licenseLinks to copyright information for the document
nextThe next document in a selection
nofollowLinks to an unendorsed document, like a paid link.("nofollow" is used by Google, to specify that the Google search spider should not follow that link)
noreferrerSpecifies that the browser should not send a HTTP referer header if the user follows the hyperlink
prefetchSpecifies that the target document should be cached
prevThe previous document in a selection
searchLinks to a search tool for the document
tagA tag (keyword) for the current document
rev text Not supported in HTML5. Specifies the relationship between the linked document and the current document
shape default
rect
circle
poly
Not supported in HTML5. Specifies the shape of a link
type MIME_type The MIME type of the linked document. Look at IANA MIME types for a complete list of standard MIME types
Reference: w3schools.com w3.org