iam_clint 1,208
Recognized Expert Top Contributor
AJAX Basic Example -
<script>
-
//set the variables.
-
function getArticle(id) {
-
var link = "/getNews.asp";
-
xmlhttpPost(link, id);
-
}
-
-
//Make the actual connection.
-
function xmlhttpPost(strURL, id) {
-
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) { //ready state 4 means its complete.
-
updatepage(self.xmlHttpReq.responseText);
-
}
-
}
-
self.xmlHttpReq.send(getquerystring(id));
-
}
-
-
//set the query string to be sent
-
function getquerystring(id) {
-
qstr = 'data=' + escape(id); // NOTE: no '?' before querystring
-
return qstr;
-
}
-
-
//put the data on the page.
-
function updatepage(str) {
-
document.getElementById("data").innerHTML = str;
-
}
-
</script>
-
<select onchange="getArticle(this.value);">
-
<option value="1">Train hits car</option>
-
<option value="2">Airplane Crashes</option>
-
<option value="3">Mental Health</option>
-
</select>
-
<div id="data"></div>
-
Now for the getNews.asp --- not fully functional code but an example -
<%
-
news_id = request("id")
-
strSQL = "select * from news where news_id = " & new_id
-
rs.open strSQL, connection, 1, 1
-
if not rs.eof then
-
response.write rs("story")
-
end if
-
%>
-
20 33089
Mind saying what the code dose?
iam_clint 1,208
Recognized Expert Top Contributor acoder 16,027
Recognized Expert Moderator MVP
Mind saying what the code dose?
It gets the news articles from a database by selecting from a drop down without having to refresh/reload the page.
If you don't know Ajax is, maybe you should check out some tutorials.
Sorry for my noobness. I looked at some AJAX tutorials and this makes a lot more sense but a few things I still don't get...
acoder 16,027
Recognized Expert Moderator MVP
Sorry for my noobness. I looked at some AJAX tutorials and this makes a lot more sense but a few things I still don't get...
Like ?
Eh, I just needa study the code more...
- ajax=function(strURL,sSend){
-
var xmlHttpReq=false
-
var self=this
-
if (window.XMLHttpRequest)self.xmlHttpReq=new XMLHttpRequest()
-
else if(window.ActiveXObject)self.xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP")
-
self.xmlHttpReq.open('POST',strURL,false)
-
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
-
self.xmlHttpReq.onreadystatechange=function(){
-
if (self.xmlHttpReq.readyState==4){
-
ajax.resul=self.xmlHttpReq
-
}
-
}
-
self.xmlHttpReq.send(sSend)
-
}
-
Hello i have made a little change on the main function, so you can use it like this: - function getArticle(id){
-
ajax('dataExample.php',id) // php,asp,...
-
alert(ajax.resul.responseText)
-
}
-
Not a big deal but now you can use the data loaded directly with the javascript, and no need to load the data into a div continer, i hope it can be helpfull
Sorry o forgot to tell that i couldn't make it work with Firefox, it works only with ie, if some one find a way.. please :)
acoder 16,027
Recognized Expert Moderator MVP
Sorry o forgot to tell that i couldn't make it work with Firefox, it works only with ie, if some one find a way.. please :)
ajax.resul.resp onseText is only available after the readyState is 4, so the call must be made within the anonymous function onreadystatecha nge or a function within that anon. function.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: cbmeeks |
last post by:
I am trying to learn AJAX to do some cool stuff over the internet. So,
for practise, I decided to code a small site that simply prints out
quotes from William Shakespeare.
http://eblarg.com/quotes/quotes.aspx
Basically, start typing away and watch the quotes appear. See how many
you can guess!
If this becomes popular, I will add tons more quotes.
|
by: aaronwmail-usenet |
last post by:
I've published sample code that uses Python
on the server side to implement AJAX
type ahead completion for web forms. Please see
documentation with links to examples and downloads at
http://xsdb.sourceforge.net/xFeed.html
"Type ahead completion" is a form of AJAX
(asyncronous javascript with XML) functionality
where the page attempts to suggest completions
|
by: aaronwmail-usenet |
last post by:
xFeed AJAX data publication example code with
documentation is available:
See http://xsdb.sourceforge.net/xFeed.html for documentation.
See http://www.xFeedMe.com for live web page examples.
See http://sourceforge.net/project/showfiles.php?group_id=93603 to
download.
The xFeed example application of the
|
by: dileep |
last post by:
I am new to Ajax and i found some good tutorials from the net.but when i
downloaded the basic sample examples and try to execute i get the error
"specified file not found", even though the files are placed in the
same folder itself.i checked the whole code again and again but could
not do anything.Can any one please help me out with this.
Is it necessary to have a separate server to execute these examples as
i have just downloaded the...
|
by: meltedown |
last post by:
This is supposed ot be an example:
http://www.ajaxtutorial.net/index.php/2006/11/30/simple-ajax-using-prototype-part-2/
It says :
This example is probably the simplest example you will ever find.
We are going to use the prototype feature ‘ajax.Updater’ (see part one
for more details on prototype).
| |
by: RamananKalirajan |
last post by:
Hi Guys I am new to AJAX. I am in need of an AJAX example which includes Prototype. My Requirement is from a prototype i must create a AJAX call and call a HTML file or Java file without server and print the response back in the caller file. If you guys can help me put pls help me
Regards
Ramanan Kalirajan
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |