Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run ajax program

 
Suganya Rajarethinam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to the Ajax program. I have one simple Ajax program.But i didn't know how to run this program.What are the requirements are needed to run the Ajax program.Can any one help to me.. Here am sending that program.

<html>
<head>
<title>Request External Web Page containing parameters using Ajax</title>
<script language="javascript" type="text/javascript">
function makeRequest(url, containerid, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}

function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
result = http_request.responseText;
document.getElementById('content').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}
</script>
</head>
<body>
<a href="javascript: makeRequest('http://www.expertsforge.com/fullstory.asp','content','?topicid=8');">Request Page</a>
<div id="content"></div>
</body>
</html>
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read this to understand the concept.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not call another domain with Ajax. Is that your issue with running tat example?

Eric
 
Suganya Rajarethinam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply....



Regards,
Suganya R.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic