Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > HTML, XML, Javascript, AJAX

Reply
 
LinkBack Thread Tools Display Modes
Old 02-18-2009, 10:50 PM   #1 (permalink)
jackrajiv
Recruit
 
Join Date: Feb 2009
Posts: 3
jackrajiv is on a distinguished road
dynamically get values form database using ajax ?

Hello,

I want to dynamically get values from database for my form. Its possible without page reloading using ajax ?

________________
website design kelowna
jackrajiv is offline   Reply With Quote
Old 02-19-2009, 02:49 PM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 841
DJMaze is on a distinguished road
yes it is possible
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-10-2009, 06:31 AM   #3 (permalink)
adetamor
Recruit
 
Join Date: Mar 2009
Posts: 2
adetamor is on a distinguished road
Its pretty easy. Just mix AJAX with some PHP or other server language. EX.

script.js
Code:
function init() {
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("GET", "process.php", true);
		httpObject.send(null);
		httpObject.onreadystatechange = display;
	}
}

function display() {
	if(httpObject.readyState == 4){
		document.getElementById('content').innerHTML = httpObject.responseText;
	}
}

function getHTTPObject(){
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
		else if (window.XMLHttpRequest) return new XMLHttpRequest();
		else {
			alert("Your browser does not support AJAX.");
		return null;
	}
}

var httpObject = null;

index.html
Code:
<html>
<head>
<title>AJAX with PHP</title>
<script src="script.js" type="text/javascript"></script>
</head>

<body>
</body>
</html>

<a href="javascript: init();">Link</a>
<div id="content"></div>
process.php
Code:
<?
echo('This info was pulled dynamically from AJAX');
?>
The html link calls the init() function in the js file. The init function then calls the process.php file. You can pass query strings to this file for specifics. In the PHP file, you can do all your database specifics. Just echo the desired information and the display() function will get that info from the php file and display it in the specified div.
adetamor is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql Database submision using html form/php Snot Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 1 06-13-2008 08:17 AM
AJAX newbie needs help with form validation! metazai HTML, XML, Javascript, AJAX 5 12-11-2006 05:58 AM
Filling out default info on form via Ajax wzeller HTML, XML, Javascript, AJAX 5 03-05-2006 05:26 PM
messing with form select values. falsepride HTML, XML, Javascript, AJAX 10 06-23-2005 08:54 AM
Passing Values from Popup Form to Main Form chrislopezz PHP 7 03-28-2005 12:45 PM


All times are GMT -8. The time now is 04:47 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting