Total members 11743 |It is currently Sat Sep 22, 2018 5:32 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





In this article we talk about how to integrate AJAX and ASP. AJAX technology allows you to update a part on your webpage without reloading the page. The client AJAX script side is the same when using different technologies such as PHP, JSP and ASP.
AJAX works mainly using HTTPSML object, one of the best cases to use AJAX is where we need a database access, such as login forms, signup, and view topics. ASP script will do the job of database handling. In the following section we will discuss an AJAX-ASP example where we connect to ASP script using HTML script. ASP script page replies with a string message to the html page. I chose this example because it makes it easier to understand the concept discussed.

In AJAX side we used the HTTPSML request object; follow is the HTML code part:
Code:
<html>
<
head>
<
script type="text/javascript">
function showMessageByAjax()
{
var httpxml;
try
{
// For browser :  Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// For browser : Internet Explorer 
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("  browser does not support AJAX!");
return false;
}
}
}
function stateChanged() 
{
if(
httpxml.readyState==4)
{
document.getElementById("MsgBoxReceive").innerHTML=httpxml.responseText;
myajaxForm.reset();
}
}

function getFormData(myajaxForm) { 
var myParameters 
= new Array(); 
for 
(var i=; i < myajaxForm.elements.length; i++) { 
var sParam 
= encodeURIComponent(myajaxForm.elements[i].name); 
sParam 
+= "="; 
sParam 
+= encodeURIComponent(myajaxForm.elements[i].value); 
myParameters
.push(sParam); 
} 
return myParameters
.join("&"); 
} 



var url
="showMessage.asp";
var myajaxForm = document.forms[0]; 
var parameters
=getFormData(myajaxForm);
httpxml.onreadystatechange=stateChanged;
httpxml.open("POST", url, true)
httpxml.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
httpxml.send(parameters) 
}

</script>
<body>
<div id=”f1” style="  background-color: #fffff1; border: 1px none #CCCCCC">
<form name="myajaxForm" onsubmit="showMessageByAjax (this.form); return false">
<input type=”submit” value=”Submit”>
</form>
</div>
<div id="MsgBoxReceive "><b>Display message here</b></div>
</body>
</html>

Following is ASP script code (showMessage.asp):
Code:
<%
Response.Write "Hello World"
%>  

We used POST method and AJAX get and at form.




Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : using ajax with asp
 What is AJAX, How to start AJAX?     -  
 need help in ajax     -  
 need help in ajax     -  
 AJAX WITH JSP     -  
 Ajax without javascript     -  
 How asynchronous is AJAX     -  
 pre caching using ajax     -  
 login using Ajax     -  
 Validation using Ajax     -  
 My First Ajax application     -  



Topic Tags

ASP AJAX, AJAX






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com