Skip to main content

Posts

Showing posts with the label Ajax

How to return data from ajax call

In this post,I will show you how to return data from ajax request.As you know that you can not return data from ajax request but if you want to perform some action on return data of ajax.The better approach is to organize your code properly around callbacks. In the example,you can make GetUsers accept a callback and use it as success callback.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReturnAjax.aspx.cs" Inherits="ReturnAjax" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><scripttype="text/javascript"src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <title></title> <script type="text/javascript"> $(document).ready(function () {�����…

How To Check That Your Browser support ajax

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>Untitled Page</title><scripttype = "text/javascript">function GetXmlHttpObject() { var xml_Http = null; try { // Firefox, Opera 8.0+, Safari xml_Http = new XMLHttpRequest(); } catch (e) { // Internet Explorertry { xml_Http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xml_Http = new ActiveXObject("Microsoft.XMLHTTP"); } } return xml_Http; } function check() { window.xmlHttp = GetXmlHttpObject(); if (window.xmlHttp == null) { alert ("Your browser does not support AJAX!"); returnnull; } else { alert("Your Browser support ajax"); } } </script></head><bodyonload="check();"></body></…

How To Use ASP.NET and HTTPrequest POST method

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserCheck.aspx.cs" Inherits="UserCheck" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title><scripttype = "text/javascript">function validateuserid(suserid) { document.body.style.cursor = 'wait'; // Create an instance of the XML HTTP Request objectvar oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" ); //debugger;// Prepare the XMLHTTP object for a HTTP POST to our validation ASP.net pagevar sURL = "http://localhost/MyPractice/check.aspx"; oXMLHTTP.open( "POST", sURL, false ); oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // Execute the reques…

How TO Use XMLHTTP Object in C#

Step 1 . Add a reference to the Microsoft,Ver3.0 (Msxml 3/4) in your project Step 2.Import the namespace using MSXML2; <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MSXML.aspx.cs" Inherits="MSXML" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/></div></form></body></html>using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System…

How To Create Ajax Based Search Page using xmlHTTP

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>

<scripttype="text/javascript">
//global variable for hold XMLHttpRequest Object
var xmlHttp;
//Creating and setting the instance of appropriate XMLHTTP Request object to a "xmlHttp" variable
function CreateXmlHttp() {
//Creating object of XMLHTTP in IE
try {
//it will work if IE have JavaScript version 5.0
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc) {
xmlHttp = null;
}
}
//Creating object of XMLHTTP for non-IE browsers
if(…

Asynchronous Request to Server (JavaScript)

I this post i will show how to send Asynchronous Request to Server which will Query the Database for certain information. Here, I am giving one example, which will send an Asynchronous Request to server for Checking the availablity of the Customerid by the user against database.

Step1.Create a new page(Async.aspx) and write down following code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Async.aspx.cs" Inherits="Async" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<scripttype="text/javascript">
function CheckUserNameAvailablity1()
{
var name=document.getElementById('<%=TextBox1.ClientID%>').value;
CheckUserNameAvailablity2(name);
returnfalse;
}
function CheckUserName…

Autosugget Using xmlHTTP in Asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoSuggest.aspx.cs" Inherits="AutoSuggest" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>

<scripttype="text/javascript">
var req;

function Initialize()
{
try
{
req=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
req=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
req=null;
}
}

if(!req && typeof XMLHttpRequest!="undefined")
{
req= new XMLHttpRequest();

}

} function SendQuery(key)
{
Initialize();
var url="http://localhost/MyPractice/AutoSuggest.aspx?k="+key;
//debugger;
if(req!=null)
{
req.onreadystatechange = Process;
req.open("GET", u…

Performing a Server Request Asynchronously

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="XmlHTTP2.aspx.cs" Inherits="XmlHTTP2" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>

<scripttype = "text/javascript"language="javascript">
var xmlHttpObj;
if (window.ActiveXObject) {
try {
xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
}
}
else xmlHttpObj = new XMLHttpRequest();
function LoadCustomers() {
if (xmlHttpObj) {
// We want this request synchronous
xmlHttpObj.open("GET", "http://" + location.host + "/MyPractice/DataFile.xml", false);
// Execute the request
xmlHttpObj.send(null);
// If the …