Possible Duplicate:
javascript ajax request without framework
How can I make the JQuery Ajax call below without using JQuery or any other library but a by only using JavaScript built-in functions?
var input = '{
"age":100,
"name":"foo",
"messages":["msg 1","msg 2","msg 3"],
"favoriteColor" : "blue",
"petName" : "Godzilla",
"IQ" : "QuiteLow"
}';
var endpointAddress = "http://your.server.com/app/service.svc";
var url = endpointAddress + "/FindPerson";
$.ajax({
type: 'POST',
url: url,
contentType: 'application/json',
data: input,
success: function(result) {
alert(JSON.stringify(result));
}
});
jQuery does a good job normalizing all the little quirks and nuonces between browsers for ajax calls.
I'd suggest finding a stand-alone ajax library that can do the same thing but without all the extra overhead jQuery brings with it. Here are a few:
Try this Example
First You have to create object of window.XMLHttpRequest
or ActiveXObject (for IE)
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Then You can send the request
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
At last You can Get the responce
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With