|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Jan 2001
Messaggi: 64
|
[AJAX]
salve a tutti!
Da poco ho deciso di arricchire le mie pagine web con ajax e mi sono subito arenato su un problema;le funzioni javascript per la gestione in ajax sono queste: Codice:
function createXMLHttpRequest()
{
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function getNote(element) {
createXMLHttpRequest();
var url = "modules.php?op=modload&name=assistenza&file=note&key_note=" + escape(element.id);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = handleNote(element.id);
xmlHttp.send(null);
}
function handleNote(note_id)
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
setNote(xmlHttp.responseXML);
}
}
}
function setNote(courseNote) {
var id_nota = courseNote.getElementsByTagName("id_nota")[0].firstChild.data;
var data_get = courseNote.getElementsByTagName("data")[0].firstChild.data;
//document.getElementById("div_3").innerHTML = xmlHttp.responseText;
alert("notA4:"+ id);
}
Codice:
function handleNote(note_id) {
alert("ID: "+note_id);
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
setNote(xmlHttp.responseXML);
}
}
}
Codice:
function handleNote(note_id) {
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
alert("ID: "+note_id);
setNote(xmlHttp.responseXML);
}
}
}
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Aug 2003
Città: Lugano (Svizzera)
Messaggi: 598
|
Ciao,
se fai un alert sullo status cosa visualizza? Andando a memoria mi sembra che possa restituire sia 200 che 0, quindi se ricordo bene prova a modificare la condizione con Codice:
if (xmlHttp.status == 200 || xmlHttp.status == 0)
__________________
XBox GamerTag : Black CrB | PSN : Black_CrB | Steam : CrB® |
|
|
|
|
|
#3 |
|
Bannato
Iscritto dal: Sep 2007
Messaggi: 39
|
Lo status 200 te lo da se va a buon fine la richiesta, prova a mettere un else
e vedi se ti da il messaggio Codice:
function handleNote(note_id) {
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
alert("ID: "+note_id);
setNote(xmlHttp.responseXML);
}else{
alert("ERRORE");
}
}
}
|
|
|
|
|
|
#4 |
|
Bannato
Iscritto dal: Sep 2007
Messaggi: 39
|
Prova a togliere il parametro alla funzione che gestisce la risposta
|
|
|
|
|
|
#5 | |
|
Member
Iscritto dal: Jan 2001
Messaggi: 64
|
Quote:
Codice:
function handleNote(note_id)
{
if (xmlHttp.readyState == 4)
{
alert("ID: "+note_id);
if (xmlHttp.status == 200)
{
setNote(xmlHttp.responseXML);
}
}
}
se tolgo tutti i vari IF Codice:
function handleNote(note_id)
{
if (xmlHttp.readyState == 4)
{
alert("ID: "+note_id);
if (xmlHttp.status == 200)
{
setNote(xmlHttp.responseXML);
}
}
}
CODE] function handleNote() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { setNote(xmlHttp.responseXML); } } } [/code] il codice funziona ma non è corretto perchè io voglio passargli l'ID. |
|
|
|
|
|
|
#6 |
|
Bannato
Iscritto dal: Sep 2007
Messaggi: 39
|
Visto che oggi nn avevo proprio niente da fare ti ho preparato questo esempio... dovrebbe fare al caso tuo, devi cambiare solo l'url e la gestione della risposta, però il grosso è fatto.
Codice:
<html>
<head>
<script type="text/javascript">
var xmlhttp
var url="Test";
function getNote(obj){
xmlhttp=null
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest()
}else if (window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
if (xmlhttp!=null){
xmlhttp.onreadystatechange=function(){handleNote(obj);}
xmlhttp.open("GET",url,true)
xmlhttp.send(null)
}else{
alert("Il browser non supporta XMLHTTP.")
}
}
function handleNote(obj){
if (xmlhttp.readyState==4){
if (xmlhttp.status==200){
obj.innerHTML=xmlhttp.status + " " + xmlhttp.responseText
}else{
alert("Errore di connessione :" + xmlhttp.statusText)
}
}
}
</script>
</head>
<body>
<h2>HttpRequest</h2>
<p><b><a href="#" onclick="getNote(document.getElementById('A1'))">Nota:</a></b>
<span id="A1"></span>
</p>
<p><b><a href="#" onclick="getNote(document.getElementById('A2'))">Nota:</a></b>
<span id="A2"></span>
</p>
</body>
</html>
|
|
|
|
|
|
#7 | |
|
Member
Iscritto dal: Jan 2001
Messaggi: 64
|
Quote:
|
|
|
|
|
|
|
#8 |
|
Bannato
Iscritto dal: Sep 2007
Messaggi: 39
|
Bene, poi mi dai il link cosi vedo come sta venendo
|
|
|
|
|
|
#9 |
|
Member
Iscritto dal: Jan 2001
Messaggi: 64
|
|
|
|
|
|
|
#10 |
|
Bannato
Iscritto dal: Sep 2007
Messaggi: 39
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 09:57.




















