- Timestamp:
- 2017-03-27T21:39:33+13:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/gsajaxapi.js
r31527 r31542 167 167 // http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp 168 168 this.urlPostSync = function(scriptURL, params) { 169 170 171 // Firefox, Opera 8.0+, Safari172 xmlHttp=new XMLHttpRequest();173 174 175 // Internet Explorer176 try {177 178 }179 catch (e) {180 181 182 183 184 185 186 187 }188 189 190 191 192 193 194 195 params += "&un=" + un_;196 197 198 params += "&ky=" + ky_;199 200 201 202 203 204 205 206 }169 var xmlHttp=false; 170 try { 171 // Firefox, Opera 8.0+, Safari 172 xmlHttp=new XMLHttpRequest(); 173 } 174 catch (e) { 175 // Internet Explorer 176 try { 177 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 178 } 179 catch (e) { 180 try { 181 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 182 } 183 catch (e) { 184 alert("Your browser does not support AJAX!"); 185 return false; 186 } 187 } 188 } 189 190 // e.g. scriptURL: /greenstone/cgi-bin/metadata-server.pl 191 xmlHttp.open('POST', scriptURL, false); // false means synchronous 192 xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 193 194 if(un_ != null) { 195 params += "&un=" + un_; 196 } 197 if(ky_ != null) { 198 params += "&ky=" + ky_; 199 } 200 201 xmlHttp.send(params); // needs to be escaped/encoded 202 203 //alert(scriptURL + "?" + params); 204 //alert(xmlHttp.responseText); // if synchronous, process xmlHttp.responseText AFTER send() call 205 return xmlHttp.responseText; 206 } 207 207 208 208 // New, an Ajax Asynchronous Post method. 209 209 // For helpful links, see the urlPostSync() method above 210 210 this.urlPostAsync = function(scriptURL, params, callback) { 211 212 213 // Firefox, Opera 8.0+, Safari214 xmlHttp=new XMLHttpRequest();215 216 217 // Internet Explorer218 try {219 220 }221 catch (e) {222 223 224 225 226 227 228 229 }230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 211 var xmlHttp=false; 212 try { 213 // Firefox, Opera 8.0+, Safari 214 xmlHttp=new XMLHttpRequest(); 215 } 216 catch (e) { 217 // Internet Explorer 218 try { 219 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 220 } 221 catch (e) { 222 try { 223 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 224 } 225 catch (e) { 226 alert("Your browser does not support AJAX!"); 227 return false; 228 } 229 } 230 } 231 232 233 234 // e.g. scriptURL: /greenstone/cgi-bin/metadata-server.pl 235 xmlHttp.open('POST', scriptURL, true); // true means asynchronous 236 xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 237 238 239 // If asynchronous: 240 // If the callback param is a function, we will set it up to get called when 241 // the async post has finished (is ready) 242 // if the callback parameter isn't a function, the param represents a field 243 // that we want to dynamically update when the async post process has finished 244 245 245 var typeof_callback = typeof(callback); 246 246 if ((typeof_callback == "string") || (typeof_callback == "number") || (typeof_callback == "boolean")) { 247 247 var locid = callback; 248 248 249 249 xmlHttp.onreadystatechange=function() { 250 250 if(xmlHttp.readyState==4) { … … 267 267 alert("Unrecognized type of callback value: " + typeof_callback); 268 268 } 269 270 271 params += "&un=" + un_;272 273 274 params += "&ky=" + ky_;275 276 277 278 279 280 281 }269 270 if(un_ != null) { 271 params += "&un=" + un_; 272 } 273 if(ky_ != null) { 274 params += "&ky=" + ky_; 275 } 276 //alert("Posting Async: " + scriptURL + "?" + params); 277 278 xmlHttp.send(params); // needs to be escaped/encoded 279 // if synchronous, would process xmlHttp AFTER send() call, such as by 280 // accessing xmlHttp.responseText to return that to the caller at this point. 281 } 282 282 283 283 // New
Note:
See TracChangeset
for help on using the changeset viewer.