 |
Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Comunitatea PHP Romania
|
| Subiectul anterior :: Subiectul următor |
| Autor |
Mesaj |
eskape19
Data înscrierii: 02/Oct/2004
Mesaje: 59
|
| Trimis: Lun Noi 27, 2006 4:19 pm Titlul subiectului: Transfer |
|
|
| Salutare! Am inceput sa ma joc cu tehnologia AJAX si am o problema. Daca am pe o pagina un select cu name-ul "obiect", iar methoda de acces in AJAX am pus-o GET, de ce nu merge sa folosesc $_GET['obiect']? Cum se transmit variabilele in AJAX? |
|
| Sus |
|
ExcalIbvr
Data înscrierii: 02/Mai/2004
Mesaje: 1107
Locație: Oradea
|
| Trimis: Lun Noi 27, 2006 6:24 pm Titlul subiectului: |
|
|
| Posteaza codul tau. |
|
| Sus |
|
eskape19
Data înscrierii: 02/Oct/2004
Mesaje: 59
|
| Trimis: Mar Noi 28, 2006 10:50 am Titlul subiectului: |
|
|
index.php
Cod:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script language="javascript">
function afisare_pagina(div,script){
var XMLHttp = XMLHTTP();
if(XMLHttp == null){
alert("Eroare");
return;
}
var url = script;
XMLHttp.onreadystatechange = function(){
if(XMLHttp.readyState == 1){
document.getElementById(div).innerHTML = "Loading ...";
}
if(XMLHttp.readyState == 4){
document.getElementById(div).innerHTML = XMLHttp.responseText;
}
}
XMLHttp.open("GET", url, true);
XMLHttp.send(null);
}
function XMLHTTP(){
var cerere = null;
if(window.XMLHttpRequest){
cerere = new XMLHttpRequest();
if(cerere.overrideMimeType)
cerere.overrideMimeType("text/xml");
}
else if(window.ActiveXObject){
try{
cerere = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(exception){
try{
cerere = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(exception){
alert("Nu pot crea obiect XMLHttp");
}
}
}
if(!cerere){
return false;
} else {
return cerere;
}
}
</script>
<body>
<table width="500" border="0" cellspacing="5" cellpadding="5" align="center">
<tr>
<td width="150" valign="top"><table width="150" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><a href="?tab=tab1" onclick="afisare_pagina('pagina','pagina.php?tab=tab1'); return false;">tab1</a></td>
</tr>
<tr>
<td><a href="?tab=tab2" onclick="afisare_pagina('pagina','pagina.php?tab=tab2'); return false;">tab2</a></td>
</tr>
<tr>
<td><a href="?tab=tab3" onclick="afisare_pagina('pagina','pagina.php?tab=tab3'); return false;">tab3</a></td>
</tr>
</table></td>
<td valign="top">
<div id="pagina"></div>
<div id="test"></div>
</td>
</tr>
</table>
</body>
</html>
pagina.php
Cod:
<?php
if(isset($_GET['tab']) && $_GET['tab'] != ''){
include($_GET['tab'].".php");
} else if($_GET['tab'] == '') { echo $_GET['sel2']; echo $_GET['sel']; }
?>
tab1.php
Cod:
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td>tip</td>
<td>
<select id="sel" onChange = "afisare_pagina('test', 'pagina.php?sel=' + this.value, '')" name="sel">
<option>tip 1</option>
<option>tip 2</option>
<option>tip 3</option>
</select>
</td>
</tr>
<tr>
<td>denumire</td>
<td>
<select id="sel2" onChange = "afisare_pagina('test', 'pagina.php, '')" name="sel2">
<option>denumire 1</option>
<option>denumire 2</option>
<option>denumire 3</option>
</select>
</td>
</tr>
</table>
tab2.php
Cod:
<? echo "tab2"; ?>
tab3.php
Cod:
<? echo "tab3"; ?>
in tab1.php am 2 select-uri. Valoarea primului select o trimite pentru ca trimit eu url sub forma "pagina.php?sel" + this.value
La celalalt select am url "pagina.php", si el nu stie sa foloseasca $_GET['sel2']. De ce? trebuie sa trimit eu mereu parametrii prin intermediul url-ului? Daca aveam POST cum faceam?[/quote] |
|
| Sus |
|
ExcalIbvr
Data înscrierii: 02/Mai/2004
Mesaje: 1107
Locație: Oradea
|
| Trimis: Mar Noi 28, 2006 1:40 pm Titlul subiectului: |
|
|
Nu sunt 100% sigur daca functioneaza si cu GET, dar unde ai:
Cod: XMLHttp.send(null);
Ar trebui sa ai:
Cod: XMLHttp.send(params);
Unde params e un string de genul:
Cod: var params = "tab=tab1";
Prin POST merge sigur, dar daca vorbim de semanticitate HTTP, request-ul pe care-l faci e corect cu GET. |
|
| Sus |
|
PHPRomania Bot
Bot Member
Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google |
| Trimis: Mie Dec 26, 2007 7:01 pm Titlul subiectului: Ad |
|
|
|
|
|
| Sus |
|
| |
|