[3395] | 1 | /* ----------------------------------------------------------------------------- |
---|
| 2 | file: ajax.js |
---|
| 3 | file version: 1.1.0 |
---|
| 4 | date: 2008-05-25 |
---|
| 5 | ------------------------------------------------------------------------------ |
---|
| 6 | author: grum at grum.dnsalias.com |
---|
| 7 | << May the Little SpaceFrog be with you >> |
---|
| 8 | ------------------------------------------------------------------------------ |
---|
| 9 | |
---|
| 10 | this classes provides base functions to add ajax into html page |
---|
| 11 | |
---|
| 12 | + create_httpobject provide a simple function to create an HTML request to a |
---|
| 13 | server ; return an XMLHttpRequest object (or compatible object for IE) |
---|
| 14 | |
---|
| 15 | + tHttpObject is a class providing : |
---|
| 16 | - an XMLHttpRequest object |
---|
| 17 | - |
---|
| 18 | |
---|
| 19 | ------------------------------------------------------------------------------ |
---|
| 20 | HISTORY VERSION |
---|
| 21 | v1.0.1 + [create_httpobject] overrideMimeType unknown by IE 7.0 ; |
---|
| 22 | v1.1.0 + add create_httpobject2 with mimetype parameter |
---|
| 23 | |
---|
| 24 | -------------------------------------------------------------------------- */ |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | function create_httpobject(requesttype, charset, ajaxurl, async) |
---|
| 28 | { |
---|
| 29 | return(create_httpobject2(requesttype, charset, ajaxurl, async, '')); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | function create_httpobject2(requesttype, charset, ajaxurl, async, mimetype) |
---|
| 33 | { |
---|
| 34 | if (window.XMLHttpRequest) |
---|
| 35 | { |
---|
| 36 | // IE7 & FF method |
---|
| 37 | http_request = new XMLHttpRequest(); |
---|
| 38 | } |
---|
| 39 | else |
---|
| 40 | { |
---|
| 41 | //Other IE method..... |
---|
| 42 | if (window.ActiveXObject) |
---|
| 43 | { |
---|
| 44 | try |
---|
| 45 | { |
---|
| 46 | http_request = new ActiveXObject("Msxml2.XMLHTTP"); |
---|
| 47 | } |
---|
| 48 | catch (e) |
---|
| 49 | { |
---|
| 50 | try |
---|
| 51 | { |
---|
| 52 | http_request = new ActiveXObject("Microsoft.XMLHTTP"); |
---|
| 53 | } |
---|
| 54 | catch (e) |
---|
| 55 | { |
---|
| 56 | window.alert("Your browser is unable to use XMLHTTPRequest"); |
---|
| 57 | } // try-catch |
---|
| 58 | } // try-catch |
---|
| 59 | } |
---|
| 60 | } // if-else |
---|
| 61 | |
---|
| 62 | if(charset=='') { charset='utf-8'; } |
---|
| 63 | |
---|
| 64 | http_request.onreadystatechange = function() { }; |
---|
| 65 | http_request.open(requesttype.toUpperCase(), ajaxurl, async); |
---|
| 66 | |
---|
| 67 | if(mimetype=='') |
---|
| 68 | { |
---|
| 69 | mimetype='text/html'; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | try |
---|
| 73 | { |
---|
| 74 | http_request.overrideMimeType(mimetype+'; charset='+charset); |
---|
| 75 | } |
---|
| 76 | catch(e) |
---|
| 77 | { |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | if(requesttype.toUpperCase()=='POST') |
---|
| 81 | { |
---|
| 82 | http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //method to restitute an XML object ; needed for compatibility between FF&IE |
---|
| 86 | http_request.XML = httpobject_responseXML; |
---|
| 87 | |
---|
| 88 | return(http_request); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | function httpobject_responseXML() |
---|
| 93 | { |
---|
| 94 | if (document.implementation && document.implementation.createDocument) |
---|
| 95 | { |
---|
| 96 | //ff method |
---|
| 97 | return(this.responseXML); |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | //ie method |
---|
| 102 | return(xmlCreateFromString(this.responseText)); |
---|
| 103 | } |
---|
| 104 | } |
---|