Monday, May 05, 2025

Breaking News
>> Securing and encrypt View State and Cookies values  >> Page has one or more controls that do not correspond with   >> “The Controls collection cannot be modified because the control contains code blocks”  >> How to fix "Validation(): Element 'xxxx' is not supported  >> How to create a new session in ASP.NET programmatically  >> MySQL Database Backup using mysqldump command    

Editors Picks

Wednesday, December 28, 2011

Simple Javascript Ajax Example


<html>
<head>
<title>Simple Ajax Exampletitle>

<script language="Javascript">
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
var form     = document.forms['f1'];
var word = form.word.value;
qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
return qstr;
}

function updatepage(str){
document.getElementById("result").innerHTML = str;
}
script>

head>
<body>
<form name="f1">
<p>
word:
<input name="word" type="text">
<input value="Go" type="button" onclick='JavaScript:xmlhttpPost("WebFrmforTest.aspx")'>p>
<div id="result">
div>
form>
body>
html>

No comments :

Post a Comment

Contact Us

Name

Email *

Message *