Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [AJAX]Wysuwany tekst.
Skr3czu
post
Post #1





Grupa: Zarejestrowani
Postów: 215
Pomógł: 0
Dołączył: 12.03.2007

Ostrzeżenie: (0%)
-----


Witam

Jak zrobić tak, że jak kliknę w w jakiś text to z pod niego wyjedzie napis.

Takie jakby rozsuwane menu, ale ja chce, żeby to był ajax.

Pozdrawiam
Go to the top of the page
+Quote Post
Mordoran
post
Post #2





Grupa: Zarejestrowani
Postów: 81
Pomógł: 2
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Polecam lekture. http://www.w3schools.com/ajax/ajax_example_suggest.asp
nie jest dokladnie co potrzebujesz, ale mysle ze dasz rade przerobic pod siebie. Co cie wiecej nauczy.
Pozdrawiam
PS Tan na kolejnej podstronie masz skrypt php co obsluguje ten przyklad

Ten post edytował Mordoran 22.08.2007, 14:51:55
Go to the top of the page
+Quote Post
Skr3czu
post
Post #3





Grupa: Zarejestrowani
Postów: 215
Pomógł: 0
Dołączył: 12.03.2007

Ostrzeżenie: (0%)
-----


A jak to zmienić ?
Go to the top of the page
+Quote Post
Mordoran
post
Post #4





Grupa: Zarejestrowani
Postów: 81
Pomógł: 2
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Robisz 3 pliki :
1. forum.html
  1. <script src="forum.js"></script>
  2. </head>
  3.  
  4. <div onclick="showHint('parametr')">Kliknij na mnie</div>
  5.  
  6. <p><span id="txtHint"></span></p>
  7.  
  8. </body>
  9. </html>

2. forum.js
Kod
var xmlHttp

function showHint(str)
{
if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="forum.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

3. forum.php
  1. <?php
  2. header("Cache-Control: no-cache, must-revalidate");
  3.  // Date in the past
  4. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  5.  
  6. //get the q parameter from URL
  7. $q=$_GET["q"];
  8.  
  9. //lookup all hints from array if length of q>0
  10. if (strlen($q) > 0)
  11. {
  12. //jak cos od prarametru bys chcial zrobic
  13. }
  14.  
  15. //output the response
  16. // moze byc string lub zmienna ktora stringa zawiera
  17. echo 'co ma sie wyswietlic';
  18. ?>


I dziala (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Pozdro, mam nadzieje, ze to jest to o co Ci chodzilo
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.09.2025 - 15:34