1/* ******************************************************************** 2 * Creates a valid, cross-browser HTTP request object for use in Ajax 3 * web scripts. 4 * 5 * Modified from Jim Ley's implementation at jibbering.com 6 * http://www.jibbering.com/2002/4/httprequest.html 7 * 8 */ 9function getHTTPObject() { 10 var xmlhttp = false; 11 /*@cc_on 12 @if (@_jscript_version >= 5) 13 try { 14 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 15 } catch (e) { 16 try { 17 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 18 } catch (e) { xmlhttp = false; } 19 } 20 @end @*/ 21 22 if (!xmlhttp) { 23 try { 24 xmlhttp = new XMLHttpRequest(); 25 } catch (e) { 26 try { 27 xmlhttp = window.createRequest(); 28 } catch (e) { xmlhttp = false; } 29 } 30 } 31 return xmlhttp; 32} 33 34 35 36/* ******************************************************************** 37 * The code below shows how to request and recieve a response. This is 38 * a quick intro to Ajax, by B. Huisman of Evertz Microsystems Ltd. 39 * 40 * 41 42var http = getHTTPObject(); 43 44/* ******************************************************************** 45 * This function sends the Ajax request. It is usually invoked by some 46 * user action. 47 * 48 * 49function sendRequest() { 50 51 // The server-side script URI 52 var uri = "includes/ajax/example.php?arg="; 53 54 // Collect values from page 55 var values = document.getElementById("element1").value; 56 57 // You can string elements together too 58 var values = [ 59 document.getElementById("element1").value, 60 document.getElementById("element2").value 61 ]; 62 values = values.join("::"); 63 64 // Send the Ajax request 65 http.open("GET", uri + encodeURIComponent(values), true); 66 http.onreadystatechange = handleHttpResponse; 67 http.send(null); 68} 69 70/* ******************************************************************** 71 * Then this function receives the response. 72 * 73 * 74function handleHttpResponse() { 75 76 // If the request has completed 77 if (http.readyState == 4) { 78 79 // Then do something with received text... 80 var response = http.responseText; 81 82 // If the response is valid XML, you can also traverse it with DOM 83 // methods using the responseXML property 84 var responseXML = http.responseXML; 85 alert(responseXML.getElementsByTagName('item').length); 86 87 } 88} 89 90 91/* ******************************************************************** 92 * If the same function always handles the response to this request, 93 * you can avoid creating two separate functions by embedding the 94 * response handler. 95 * 96 * In this fashion, you can create the HTTP object on the fly within 97 * the scope of the function only. 98 * 99 * 100function sendRequestEmbedded() { 101 var values = "sample"; 102 103 // Create HTTP Object within the scope of this function only 104 var http = getHTTPObject(); 105 106 http.open("GET", "includes/ajax/example.php?arg=" + encodeURIComponent(values), true); 107 http.onreadystatechange = function() { 108 if (http.readyState == 4) { 109 var response = http.responseText; 110 111 // Do things... 112 } 113 }; 114 http.send(null); 115} 116 117 118/* ******************************************************************** 119 * Sending many values via GET can make for a URI which is 10km long! 120 * In such a case, you should use a POST request instead, which sends 121 * the data in one of the request headers. Doing this requires setting 122 * a Content-Type header before sending. 123 * 124 * 125function sendRequestPost() { 126 var values = [ 127 "a","b","c","d","e","f","g","h","i","j","k","l","m", 128 "n","o","p","q","r","s","t","u","v","w","x","y","z" 129 ].join("::"); 130 131 var http = getHTTPObject(); 132 133 http.open("POST", "includes/ajax/example.php", true); 134 http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 135 http.onreadystatechange = function() { 136 if (http.readyState == 4) { 137 var response = http.responseText; 138 139 // Do things... 140 } 141 }; 142 http.send("arg=" + encodeURIComponent(values)); 143} 144 145*/
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.