Wednesday, 13 March 2013

Call Ajax from Javacript


Here We can call GetBulding function of Home Class / Controller and We are passing parameter here 'inUserID' and Response will be in 'data'.

var URL = '/Home/GetBuilding';
 $.post(URL, { inUserID: 1 }, function (data) {
            alert('call')
            if (data != null) {
            }
  });

Or

 $.ajax({
                type: "POST",
                url: "",
                contentType: "application/json; charset=utf-8",
                data: {},
                success: function (data) {
                },
                error: function (xhr, ajaxOptions, thrownError) {
                       alert(xhr.responseText);
                }

});

If you can generate your URL dynamically using Url.Action method.

var URL = '/Home/GetBuilding';

For above URL you can use Url.Action method like:

var URL = "@Url.Action("GetBuilding","Home")";

which will create URL dynamically.

No comments:

Post a Comment