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
|
Ajax.Requete=Class.create();
Ajax.Requete.prototype={
demarrage: function(url, options) {
this.transport = Ajax.getTransport();
this.setOptions(options);
this.lancer(url);
},
setOptions: function(options) {
this.options = {
method: 'post',
asynchronous: true,
contentType: 'application/x-www-form-urlencoded',
encoding: 'UTF-8',
parameters: '',
}
Object.extend(this.options, options || {});
this.options.method = this.options.method.toLowerCase();
},
lancer:function(url) {
this.url = url;
this.method = this.options.method;
this.params = this.options.parameters;
this.transport.open(this.method.toUpperCase(),this.url,this.options.asynchronous);
this.setHeaders();
this.transport.send(this.params);
this.transport.onreadyStatechange=this.reponse();
},
setHeaders:function() {
this.transport.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
this.transport.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
if (this.method == 'post') {
this.transport.setRequestHeader('Content-type', this.options.contentType +'; charset='+ this.options.encoding );
if (this.transport.overrideMimeType && (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) this.transport.setRequestHeader('Connection', 'close');
}
},
reponse:function() {
if(this.transport.readyState==4) { if (this.transport.status==200) this.options.onComplete.apply(this); }
//C'est ici que ça ne change pas du tout, j'ai tjrs 1
else $('nbrFlash').innerHTML=this.transport.readyState;
}
} |
Partager