Ciao a tutti!
Ho la necessità di creare una lista all'interno di un portale Sharepoint tipo la seguente:
ID - NOME - COGNOME - LINK AL PDF
Questa lista viene caricata da una tabella esterna al portale presente in un SQL Server 2005.
Fino a questo punto tutto bene, l'unico mio problema è che il link deve funzionare solamente a patto che esista il documento PDF. Mi spiego un pochettino meglio: ad esempio per il primo nominativo con ID = 1 il documento pdf si chiamerà d0001.pdf.
Per risolvere questo problema e quindi per verificare o meno l'esistenza ho deciso di utilizzare object XMLHttpRequest. All'interno di un file .js ho scritto le seguenti righe di codice:
codice:
var xmlhttp;
function loadXMLDoc(url) {
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
if (xmlhttp!=null) {
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
function state_Change() {
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK" 404 = "File non found"
document.getElementById('A1').innerHTML=xmlhttp.status;
//document.getElementById('A2').innerHTML=xmlhttp.statusText;
//document.getElementById('A3').innerHTML=xmlhttp.responseText;
}
else
{ alert("Problem retrieving XML data: " + xmlhttp.statusText);
}
}
}
Il tutto funziona in maniera perfetta, se inserisco un alert all'interno del controllo del xmlhttp.status mi risponde perfettamente 200 o 404 (o ciò che deve rispondere...).
Il mio problema è che non riesco a restituire una variabile contenente il valore della xmlhttp.status per poterlo poi gestire in un'altra funzione.
Ad esempio se scrivo:
codice:
function state_Change() {
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK" 404 = "File non found"
document.getElementById('A1').innerHTML=xmlhttp.status;
//document.getElementById('A2').innerHTML=xmlhttp.statusText;
//document.getElementById('A3').innerHTML=xmlhttp.responseText;
var Risultato = 1; // oppure var Risultato = xmlhttp.status;
}
else
{ alert("Problem retrieving XML data: " + xmlhttp.statusText);
}
}
}
function ResultTestDoc(url) {
alert('Dentro la funzione result: '+Risultato);
}
il risultato che mi dà il browser è che la variabile Risultato non è definita.
Come posso fare, è circa due settimane che ci sbatto la testa! HELP!!!
Grazie mille!!