Bytes Tech Community, We heart tech!

Register Now


 
Reply to this topicStart new topicStart Poll

Outline · [ Standard ] · Linear+

 Getting Started with AJAX, Javascript + PHP

DooBDee
post May 5 2006, 03:22 PM
Post #1


PHP and phpBB Specialist
Group Icon

Group: VIP Members
Posts: 533
Gender: Not Telling
------------------
Donate CFX Creds
CFX Credits: 411
------------------
Member No.: 3,098

Reputation: 8 pts




Good tutorial for learning ajax guys ;)


User is offlineProfile CardPM
+Quote PostGo to the top of the page
Gareth
post Jul 31 2006, 10:50 AM
Post #2


Mr. Bling Bling :P
Group Icon

Group: Members
Posts: 7,555
Gender: Male
------------------
Donate CFX Creds
CFX Credits: 10,736
------------------
Member No.: 1

Reputation: 184 pts




That's one excellent tutorial Rexy, Ajax is becomign more and more popular - thanks :)


User is offlineProfile CardPM
+Quote PostGo to the top of the page
boyd
post Apr 5 2007, 12:57 PM
Post #3


Newbie
Group Icon

Group: Members
Posts: 1
Gender: Not Telling
------------------
Donate CFX Creds
CFX Credits: 11
------------------
Member No.: 7,188

Reputation: none




Great tutorial, first it wasn't very clear for me what and how but now it is!!


User is offlineProfile CardPM
+Quote PostGo to the top of the page
Klenuke
post Apr 11 2007, 02:11 AM
Post #4


CodedFx Legend!
Group Icon

Group: VIP Members
Posts: 1,194
Gender: Male
Sotw Wins: 1
------------------
Donate CFX Creds
CFX Credits: 571
------------------
Member No.: 6,436

Reputation: 17 pts




NVM this...


User is offlineProfile CardPM
+Quote PostGo to the top of the page
bikerjeg
post May 15 2007, 10:48 PM
Post #5


Advanced Member
Group Icon

Group: Members
Posts: 51
Gender: Not Telling
------------------
Donate CFX Creds
CFX Credits: 109
------------------
Member No.: 7,568

Reputation: none




Nice tut. I am beginning to understand a lot more now. I Really appreciate it!!!


User is offlineProfile CardPM
+Quote PostGo to the top of the page
Wicked Modz
post May 16 2007, 06:40 PM
Post #6


All your tacos belong to me!
Group Icon

Group: VIP Members
Posts: 90
Gender: Male
------------------
Donate CFX Creds
CFX Credits: 24
------------------
Member No.: 7,282

Reputation: -3 pts




Very nice!

Im still new in AJAX and i gots a quick question that is probly a simple one.

I have an ajax frame on an index(home) page.. how would i make the ajax frame automatically show a html page when the page (index) is loaded?

This is my main script-
CODE
<!--



var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_callJS(jsStr) { //v2.0
 return eval(jsStr)
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 if (restore) selObj.selectedIndex=0;
}
//-->


lets say i name a AJAX frame "homearea"
im calling through a button link (testing.html) like this
CODE
java script:ajaxpage('testing.html', 'homearea');


the thing is.. i dont know how to make the ajax frame automatically show the index page when the website is loaded.


User is offlineProfile CardPM
+Quote PostGo to the top of the page
Vakuum
post May 16 2007, 09:34 PM
Post #7


This is all a dream. None of you are real.
Group Icon

Group: Liaisons
Posts: 3,030
Gender: Male
------------------
Donate CFX Creds
CFX Credits: 1,915
------------------
Member No.: 5,346

Reputation: 26 pts




What do you mean by ajax "frame"? Are you using framesets or iframes? Cuz that isn't necessary...

I see the important part of the code here:
CODE
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

Now what you'd want to do is include the script and make an empty <div> element with id="loadstuff" ... And a link somewhat like this: <a href="#" onclick="java script:loadpage('file_name_to_include.html','loadstuff');">Load content yo</a>... Could be wrong.


User is offlineProfile CardPM
+Quote PostGo to the top of the page
Unrated
post May 17 2007, 02:15 PM
Post #8


Loyal Member
Group Icon

Group: Coders
Posts: 295
Gender: Male
------------------
Donate CFX Creds
CFX Credits: 770
------------------
Member No.: 1,958

Reputation: 18 pts




I don't think thats what he meant ,just.xTc.

He wants to know how to load a default page.

just add this at the start of your java script:
CODE

ajaxpage('index.html', 'homearea');


so when the script gets loaded the index page loads, when you click another link it should overwrite it



User is offlineProfile CardPM
+Quote PostGo to the top of the page
Wicked Modz
post May 17 2007, 05:44 PM
Post #9


All your tacos belong to me!
Group Icon

Group: VIP Members
Posts: 90
Gender: Male
------------------
Donate CFX Creds
CFX Credits: 24
------------------
Member No.: 7,282

Reputation: -3 pts




sweet thnx guys, ill test this out when i get a break at work :)

i think i tried something similar to what unrated put but most likely i did it in the wrong spot.... or didnt do it and just thought i did lol

Wicked Modz, May 17 2007, 05:44 PM:
sry for the double post, but just letting you know it works now XD

AJAX is fun lol


User is offlineProfile CardPM
+Quote PostGo to the top of the page

Reply to this topicTopic OptionsStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: