Overview of Jquery Ajax

Jquery API is extension of the JavaScript language. It supports methods which make it easy to write complex client side scripts. The creators of JQuery specifically created the library to make common tasks trivial.

Ajax is key part of the websites now a days and asynchronous JavaScript is used widely to do Ajax calls. Jquery provides easy methods which can be used to call server side functions asynchronously without writing much code.

Jquery Ajax Methods

There are following methods in Jquery which can be used for calling server side functions through Ajax-

  • jQuery.ajax( options ) Returns: XMLHttpRequest
    • Load a remote page using an HTTP request.
  • load( url, data, callback ) Returns: jQuery
    • Load HTML from a remote file and inject it into the DOM.
  • jQuery.get( url, data, callback, type ) Returns: XMLHttpRequest
    • Load a remote page using an HTTP GET request.
  • jQuery.getJSON( url, data, callback ) Returns: XMLHttpRequest
    • Load JSON data using an HTTP GET request.
  • jQuery.getScript( url, callback ) Returns: XMLHttpRequest
    • Loads, and executes, a local JavaScript file using an HTTP GET request.
  • jQuery.post( url, data, callback, type ) Returns: XMLHttpRequest
    • Load a remote page using an HTTP POST request.

Examples of method

jQuery.post( url, data, callback, type )

This method loads a remote page using an HTTP POST request.

This is an easy way to send a simple POST request to a server without having to use the more complex $.ajax function. It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful
response code).

The returned data format can be specified by the fourth parameter. If you need to have both error and success callbacks, you may want to use $.ajax. $.post is a (simplified) wrapper function for $.ajax.

Arguments

  • URL String The URL of the page to load.
  • data (Optional) Map, String Key/value pairs that will be sent to the server.
  • callback (Optional) Function A function to be executed whenever the data is loaded successfully.
    function (data, textStatus) {
    //To do
    }
  • type (Optional) String
$.post("LuxurySummary/OtherMlsCounts_SelectedIndexChanged",

"Mlscount=" + mlscount,

function(data){

process(data);

},

"html"

);

this function will call a ASP.net MVC function and pass the value of a parameter to it. Signature is given below

public string OtherMlsCounts_SelectedIndexChanged(string Mlscount)

{

try

{

}

catch (Exception ex)

{

throw ex;

}

}

Related Posts

  1. Search Engine Friendly URL (URL Mapping) in ASP.Net 2.0
  2. ASP.Net Performance Improvement Tips
  3. Checklist/Guidelines for ASP.Net Developers
  4. ASP.Net Developers Checklist – Security Checklist
  5. Pass by Value and Pass by Reference in Java

Tags: , ,

4 Comments to “Call ASP.net MVC Server side function using Jquery Ajax”

  1. des says:

    WHAT !!! Microsoft copies Java in all Manner, Even MCV is copied !!!!! What a shame!!!

  2. TimonOmsk says:

    MVC is an architectural pattern and it’s not created by Java or Sun
    http://en.wikipedia.org/wiki/Model-View-Controller

  3. saj says:

    Java is histroy now :)

  4. Hitesh says:

    Yes this model was referenced way back in 1987 in a language known as ‘Smalltalk’…

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>