Introduction:
In Ajax,we can easily fetch data’s from Server Using GET Method.
Main:
Ajax allows you to fetching data’s fro server without a page refresh.For ex,Declare one aspx page named Sample.aspx
in inline code try this below examble,
<html>
<head>
<title>Sending Data to the Server</title>
<script language="javascript">
var XMLHttpRequestObject=false;
if (window.XMLHttpRequest){
XMLHttpRequestObject = new XMLHttpRequest( );
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new
ActiveXObj ect("Microsoft.XMLHTTP");
}
function getData(dataSource, divID)
{
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);
XMLHttpRequestObject.onreadystatechange = function( )
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200){
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
</script>
</head>
<body>
<h1>Sending Data to the Server</h1>
<form>
<input type = "button" value = "Fetch message 1"
onclick = "getData('sample.txt', ‘DisplayHere’)">
</form>
<div id = "DisplayHere">
</div>
</body>
</html>
<html> <head> <title>Sending Data to the Server</title> <script language="javascript"> var XMLHttpRequestObject=false; if (window.XMLHttpRequest){ XMLHttpRequestObject = new XMLHttpRequest( ); } else if (window.ActiveXObject) { XMLHttpRequestObject = new ActiveXObj ect("Microsoft.XMLHTTP"); } function getData(dataSource, divID) { if(XMLHttpRequestObject) { var obj = document.getElementById(divID); XMLHttpRequestObject.open("GET", dataSource); XMLHttpRequestObject.onreadystatechange = function( ) { if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){ obj.innerHTML = XMLHttpRequestObject.responseText; } } XMLHttpRequestObject.send(null); } } </script> </head> <body> <h1>Sending Data to the Server</h1> <form> <input type = "button" value = "Fetch message 1" onclick = "getData('sample.txt', ‘DisplayHere’)"> </form> <div id = "DisplayHere"> </div> </body> </html> |
In DisplayHere we can see,
Hi,This is Get Method(),
Conclusion:
Hope this helps,
Happy Coding.
Great article, I especially like what you had to say in the last paragraph.
Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.
I just like the style you took with this topic. It’s not typical that you simply find something so to the point and informative.
Thank you so much…This really does make my life easier…
KOVAL ! why do you only respond to people who threaten to unsubscribe… what about me….Id like a shout out too ….I watched all your videos….TWICE…..i loved you when you weren’t? famous…. *sigh*