Autor | Zpráva | ||
---|---|---|---|
beginer Profil * |
#1 · Zasláno: 19. 11. 2011, 18:03:11
ahoj, s ajaxom len skúšam zatiaľ našiel som niekde skript na načítavanie obsahu ide to vpodstate cez jQuery resp ajax.
Kódy: index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250" /> <link rel="stylesheet" type="text/css" media="screen" href="main.css" /> </head> <body> <div id="container"> <div id="top"> <ul id="menu"> <li id="home">Home</li> <li id="news">News</li> <li id="interviews">Interviews</li> <li id="external">External</li> </ul> <span class="clear"></span> </div> <div id="loading"> <img src="css/images/loading.gif" alt="Načítavanie..." /> </div> <div id="content"> <h2>Home</h2> </div> <div id="footer"> <p>koniec</p> </div> </div> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"></script> <script type="text/javascript" src="menu.js"></script> </body> </html> </body> menu.js $(document).ready(function(){ //References var sections = $("#menu li"); var loading = $("#loading"); var content = $("#content"); sections.click(function(){ showLoading(); switch(this.id){ case "home": content.slideUp(); content.load("sections.php #section_home", hideLoading); content.slideDown(); break; case "news": content.slideUp(); content.load("sections.php #section_news", hideLoading); content.slideDown(); break; case "interviews": content.slideUp(); content.load("sections.php #section_interviews", hideLoading); content.slideDown(); break; case "external": content.slideUp(); content.load("external.php", hideLoading); content.slideDown(); break; default: //hide loading bar if there is no selected section hideLoading(); break; } }); function showLoading(){ loading .css({visibility:"visible"}) .css({opacity:"1"}) .css({display:"block"}) ; } function hideLoading(){ loading.fadeTo(1000, 0); }; }); Funguje to jednoducho cez menu sa načítava obsah s toho súboru sections.php keď tam je čisto len text tak to pekne funguje problém nastal keď som namiesto sections.php tam skúsil dať môj registračný formulár chyby: 1.nefunguje mi kódovanie windows-1250 (pritom aj vo formulári je nastavené aj index.php) 2.nedokáže načítať nič čo je v ohraničení <?php ?> čo s tým robiť? vopred ďakujem |
||
beginer Profil * |
#2 · Zasláno: 19. 11. 2011, 18:42:08
našiel som ešte efektívnejší kód ale je tam ten istý problém nedokáže (neviem prečo) načítať php, kódovanie sa mi podarilo vyriešiť už.
<head> <meta http-equiv="content-type" content="text/html; charset=windows-1250" /> <script language="JavaScript" type="text/javascript" src="ajax.js"></script> <script language="JavaScript" type="text/javascript"> function makeactive(tab) { document.getElementById("tab1").className = ""; document.getElementById("tab2").className = ""; document.getElementById("tab3").className = ""; document.getElementById("tab"+tab).className = "active"; callAjax('content.php?content= '+tab, 'content', 'getting content for tab '+tab+'. Wait...', 'Error'); } </script> </head> <body> <ul id="tabmenu"> <li onclick="makeactive(1)"><a class="" id="tab1">First Tab</a></li> <li onclick="makeactive(2)"><a class="" id="tab2">Second Tab</a></li> <li onclick="makeactive(3)"><a class="" id="tab3">Third Tab</a></li> </ul> <div id="content"></div> </body> function callAjax(url, pageElement, callMessage, errorMessage) { document.getElementById(pageElement).innerHTML = callMessage; try { req = new XMLHttpRequest(); /* e.g. Firefox */ } catch(e) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); /* some versions IE */ } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); /* some versions IE */ } catch (E) { req = false; } } } req.onreadystatechange = function() {responseAjax(pageElement, errorMessage);}; req.open("GET",url,true); req.send(null); } function responseAjax(pageElement, errorMessage) { var output = ''; if(req.readyState == 4) { if(req.status == 200) { output = req.responseText; document.getElementById(pageElement).innerHTML = output; } else { document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output; } } } <?php header("Content-Type: text/html; charset=windows-1250"); if ($_GET['content'] == 1) { echo 'Content for Page 1'; } if ($_GET['content'] == 2) { echo 'Content for Page 2'; } if ($_GET['content'] == 3) { echo 'Content For Page 3'; } ?> To zobrazí ale nejaký dlhší kód php teda formulár celý nezobrazí nič |
||
Str4wberry Profil |
#3 · Zasláno: 21. 11. 2011, 23:52:57
Můžeš nějak vysvětlit tu poslední větu? Nejsem z ní dvakrát moudrý.
|
||
beginer Profil * |
#4 · Zasláno: 22. 11. 2011, 07:15:42
Načítaval som ten php formulár , ale nikdy nič nenačitalo iba html.Problém bol vtom že som tam mal <form> keď som to odstránil už načítalo všetko.
|
||
Časová prodleva: 12 let
|
0