Search This Blog

Tuesday, August 16, 2016

Introduction to Ajax and Its Pros and Cons


Ajax in nothing but short form of Asynchronous JavaScript And XML.By using Ajax we can Post and Get the data without fully page load event .Ajax implementation uses JavaScript functions to call methods from a web service, webpage request in response to get response.

Ajax Syntax for C# .NET-

function MyFunction(Param1, Param2) {      
        type: "POST",
        url: "MyPage.aspx/MyMethod",
        data: "{ Param1: '" + Param1+ "',Param2: '" + Param2 + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            // On success                 
        Error: function (x, e) {
            // On Error
type-Type of request Get or Post.
Url-Requested Page URL.
Data- Parameter to pass to the requested function.
ContentType-Encoding type.
DataType-Data format it may be XML/JSON.
Success-What needs to be done on success of ajax call.
Error- What needs to be done on failure of ajax call  

Advantages of AJAX

  • Reduce the traffic travels between the client and the server.
  • Response time is faster so increases performance and speed.
  • We can use JSON(JavaScript Object Notation) which is alternative to XML. JSON is key value pair and works like an array.
  • We can use Firefox browser with an add-on called as Firebug to debug all Ajax calls.
  • AJAX communicates over HTTP Protocol.

Disadvantages of AJAX

  • JavaScript disabled browsers cannot use the application.
  • It can increase design and development time
  • More complex than building classic web application
  • Security is less in AJAX application as all files are downloaded at client side.
  • Search Engine like Google cannot index AJAX pages.We cannot Bookmark AJAX URL because It might be same for more then one page.

No comments:

Post a Comment