News
IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. ***
  Jan 3 2015 10:32PM     John
  0 Comments    1042 Views  
Here you can see the simple code for Ajax in JavaScript. Before using Ajax, you need to add the AjaxControlToolKit.ddl to your bin folder.
You can download from the below link, Click Here
HTML

<html>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" value="Save" class="sub" onclick="ajaxCallMethod()" />
    </div>
    </form>
</body>

CSS

<style type="text/css">
        .btn
        {
            line-height: 2.0;
            border-radius: 4px;
            border: none;
            font-size: 14px;
            cursor: pointer;
            color: #fff;
            background-color: #00a9da;
            border-color: #0094bf;
        }

</style>

Java Script

<script language="javascript" type="text/javascript">
        var xmlHttp;
        function ajaxCallMethod() {
            try {
                xmlHttp = GetXmlHttpObject();
                if (xmlHttp == null) {
                    alert("Your browser does not support AJAX!");
                    return;
                }
                var url = 'AjaxCall-Javascript.aspx?Pagename=js';
                xmlHttp.onreadystatechange = function () {
                    if (xmlHttp.readyState == 4) {
                        if (xmlHttp.status == 200) {
                            alert(xmlHttp.responseText);
                        }
                        if (xmlHttp.readyState == 4) {
                            // LoadingPage();
                        }
                    }
                }
                xmlHttp.open("POST", url, true);
                xmlHttp.send(null);
                if (xmlHttp.readyState == 1) {
                    //alert('Loading');
                }
            } catch (e) {
                alert(e.Message);
            }
        }
    </script>

You can also pass parameter to the page using Query String “Pagename” , shown in above method.

function GetXmlHttpObject() {
            var xmlHttp = null;
            try {
                xmlHttp = new XMLHttpRequest();
            }
            catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
            }
            return xmlHttp;
        }

C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AjaxCall_Javascript : System.Web.UI.Page
{
    string returnvalue = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if ((Request.QueryString["Pagename"] == "js"))
            {
                returnvalue = "Server Responded - The Developer Tips";
                Response.ContentType = "text/XML";
                Response.Write(returnvalue);
                Response.End();
            }
        }
    }
}

Demo
You can see live Ajax call demo from clicking the below Submit button and getting response from server without page reload.

Hi, This is John.I hope this page will helps you to create simple page with JavaScript Ajax.Thanks.
BackToTop
Comments



 
Search
1&1 Hosting
Recent Posts
Bind Gridview from CSV file in Asp.Net C#
Jun 18 2016 11:38PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Feb 27 2016 11:51AM Posted By John
Gridview custom CSS in ASP.Net
Feb 25 2016 10:59AM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Feb 25 2016 10:20AM Posted By Micheal
Read excel file and convert to List in C#
Feb 25 2016 6:26AM Posted By Michael
Encryption and Decryption for Password in C#
Feb 17 2016 3:52AM Posted By Michael
How to create Chart in ASP.Net C#
Feb 16 2016 8:03AM Posted By Michael Ryan
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: