1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/* ------------------------------------------------------------------------------------------------------------
ProxyLoadXML(url, addData)
loads an XML document from the given url and returns its reference
(object XMLDocument)
Actually, this function performs like LoadXML, but url is reached by the
meaning of a PHP 'proxy' (proxy.php), to allow cross sites access.
addData stands for passing extra parameters (a string with parameters
separated by semi-colons)
if addData is set (aka length > 0), each parameter POST-transmitted this way :
param0 = ...1st parameter...
param1 = ...2nd parameter...
...
---------------------------------------------------------------------------------------------------------------- */
function ProxyLoadXML(url, addData) {
var xhr = CreateAjax();
var postVars = 'uri='+url;
// traitement des paramètres aditionnels
if(addData.length) {
var reg=new RegExp("[;]+", "g");
var params = new Array;
params = addData.split(reg);
for (var i = 0; i < params.length; i++) {
postVars += '¶m' + i + '=' + params[i];
}
}
xhr.open("POST", 'proxy.php?'+urlend() , false);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.setRequestHeader("Content-length", postVars.length);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('Accept', 'text/javascript, text/html, text/plain, application/xml, text/xml, */*');
xhr.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
/* 4 : état "complete" */
if (xmlhttp.status != 200) {
// 200 : code HTTP pour OK
// Traitement de la réponse. Ici on affiche la réponse dans une boîte de dialogue.
alert('Le serveur a renvoyé une erreur.');
}
}
}
xhr.send(postVars);
return xhr.responseXML;
} |
Partager