in plugins/struts2-dojo-plugin/src/main/resources/org/apache/struts2/static/dojo/dojo.js.uncompressed.js [4680:4940]
this.bind = function(/*dojo.io.Request*/kwArgs){
//summary: function that sends the request to the server.
//This function will attach an abort() function to the kwArgs dojo.io.Request object,
//so if you need to abort the request, you can call that method on the request object.
//The following are acceptable properties in kwArgs (in addition to the
//normal dojo.io.Request object properties).
//url: String: URL the server URL to use for the request.
//method: String: the HTTP method to use (GET, POST, etc...).
//mimetype: Specifies what format the result data should be given to the load/handle callback. Valid values are:
// text/javascript, text/json, application/json, application/xml, text/xml. Any other mimetype will give back a text
// string.
//transport: String: specify "XMLHTTPTransport" to force the use of this XMLHttpRequest transport.
//headers: Object: The object property names and values will be sent as HTTP request header
// names and values.
//sendTransport: boolean: If true, then dojo.transport=xmlhttp will be added to the request.
//encoding: String: The type of encoding to use when dealing with the content kwArgs property.
//content: Object: The content object is converted into a name=value&name=value string, by
// using dojo.io.argsFromMap(). The encoding kwArgs property is passed to dojo.io.argsFromMap()
// for use in encoding the names and values. The resulting string is added to the request.
//formNode: DOMNode: a form element node. This should not normally be used. Use new dojo.io.FormBind() instead.
// If formNode is used, then the names and values of the form elements will be converted
// to a name=value&name=value string and added to the request. The encoding kwArgs property is used
// to encode the names and values.
//postContent: String: Raw name=value&name=value string to be included as part of the request.
//back or backButton: Function: A function to be called if the back button is pressed. If this kwArgs property
// is used, then back button support via dojo.undo.browser will be used. See notes for dojo.undo.browser on usage.
// You need to set djConfig.preventBackButtonFix = false to enable back button support.
//changeUrl: boolean or String: Used as part of back button support. See notes for dojo.undo.browser on usage.
//user: String: The user name. Used in conjuction with password. Passed to XMLHttpRequest.open().
//password: String: The user's password. Used in conjuction with user. Passed to XMLHttpRequest.open().
//file: Object or Array of Objects: an object simulating a file to be uploaded. file objects should have the following properties:
// name or fileName: the name of the file
// contentType: the MIME content type for the file.
// content: the actual content of the file.
//multipart: boolean: indicates whether this should be a multipart mime request. If kwArgs.file exists, then this
// property is set to true automatically.
//sync: boolean: if true, then a synchronous XMLHttpRequest call is done,
// if false (the default), then an asynchronous call is used.
//preventCache: boolean: If true, then a cache busting parameter is added to the request URL.
// default value is false.
//useCache: boolean: If true, then XMLHttpTransport will keep an internal cache of the server
// response and use that response if a similar request is done again.
// A similar request is one that has the same URL, query string and HTTP method value.
// default is false.
if(!kwArgs["url"]){
// are we performing a history action?
if( !kwArgs["formNode"]
&& (kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"] || kwArgs["watchForURL"])
&& (!djConfig.preventBackButtonFix)) {
dojo.deprecated("Using dojo.io.XMLHTTPTransport.bind() to add to browser history without doing an IO request",
"Use dojo.undo.browser.addToHistory() instead.", "0.4");
dojo.undo.browser.addToHistory(kwArgs);
return true;
}
}
// build this first for cache purposes
var url = kwArgs.url;
var query = "";
if(kwArgs["formNode"]){
var ta = kwArgs.formNode.getAttribute("action");
if((ta)&&(!kwArgs["url"])){ url = ta; }
var tp = kwArgs.formNode.getAttribute("method");
if((tp)&&(!kwArgs["method"])){ kwArgs.method = tp; }
query += dojo.io.encodeForm(kwArgs.formNode, kwArgs.encoding, kwArgs["formFilter"]);
}
if(url.indexOf("#") > -1) {
dojo.debug("Warning: dojo.io.bind: stripping hash values from url:", url);
url = url.split("#")[0];
}
if(kwArgs["file"]){
// force post for file transfer
kwArgs.method = "post";
}
if(!kwArgs["method"]){
kwArgs.method = "get";
}
// guess the multipart value
if(kwArgs.method.toLowerCase() == "get"){
// GET cannot use multipart
kwArgs.multipart = false;
}else{
if(kwArgs["file"]){
// enforce multipart when sending files
kwArgs.multipart = true;
}else if(!kwArgs["multipart"]){
// default
kwArgs.multipart = false;
}
}
if(kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"]){
dojo.undo.browser.addToHistory(kwArgs);
}
var content = kwArgs["content"] || {};
if(kwArgs.sendTransport) {
content["dojo.transport"] = "xmlhttp";
}
do { // break-block
if(kwArgs.postContent){
query = kwArgs.postContent;
break;
}
if(content) {
query += dojo.io.argsFromMap(content, kwArgs.encoding);
}
if(kwArgs.method.toLowerCase() == "get" || !kwArgs.multipart){
break;
}
var t = [];
if(query.length){
var q = query.split("&");
for(var i = 0; i < q.length; ++i){
if(q[i].length){
var p = q[i].split("=");
t.push( "--" + this.multipartBoundary,
"Content-Disposition: form-data; name=\"" + p[0] + "\"",
"",
p[1]);
}
}
}
if(kwArgs.file){
if(dojo.lang.isArray(kwArgs.file)){
for(var i = 0; i < kwArgs.file.length; ++i){
var o = kwArgs.file[i];
t.push( "--" + this.multipartBoundary,
"Content-Disposition: form-data; name=\"" + o.name + "\"; filename=\"" + ("fileName" in o ? o.fileName : o.name) + "\"",
"Content-Type: " + ("contentType" in o ? o.contentType : "application/octet-stream"),
"",
o.content);
}
}else{
var o = kwArgs.file;
t.push( "--" + this.multipartBoundary,
"Content-Disposition: form-data; name=\"" + o.name + "\"; filename=\"" + ("fileName" in o ? o.fileName : o.name) + "\"",
"Content-Type: " + ("contentType" in o ? o.contentType : "application/octet-stream"),
"",
o.content);
}
}
if(t.length){
t.push("--"+this.multipartBoundary+"--", "");
query = t.join("\r\n");
}
}while(false);
// kwArgs.Connection = "close";
var async = kwArgs["sync"] ? false : true;
var preventCache = kwArgs["preventCache"] ||
(this.preventCache == true && kwArgs["preventCache"] != false);
var useCache = kwArgs["useCache"] == true ||
(this.useCache == true && kwArgs["useCache"] != false );
// preventCache is browser-level (add query string junk), useCache
// is for the local cache. If we say preventCache, then don't attempt
// to look in the cache, but if useCache is true, we still want to cache
// the response
if(!preventCache && useCache){
var cachedHttp = getFromCache(url, query, kwArgs.method);
if(cachedHttp){
doLoad(kwArgs, cachedHttp, url, query, false);
return;
}
}
// much of this is from getText, but reproduced here because we need
// more flexibility
var http = dojo.hostenv.getXmlhttpObject(kwArgs);
var received = false;
// build a handler function that calls back to the handler obj
if(async){
var startTime =
// FIXME: setting up this callback handler leaks on IE!!!
this.inFlight.push({
"req": kwArgs,
"http": http,
"url": url,
"query": query,
"useCache": useCache,
"startTime": kwArgs.timeoutSeconds ? (new Date()).getTime() : 0
});
this.startWatchingInFlight();
}else{
// block async callbacks until sync is in, needed in khtml, others?
_this._blockAsync = true;
}
if(kwArgs.method.toLowerCase() == "post"){
// FIXME: need to hack in more flexible Content-Type setting here!
if (!kwArgs.user) {
http.open("POST", url, async);
}else{
http.open("POST", url, async, kwArgs.user, kwArgs.password);
}
setHeaders(http, kwArgs);
http.setRequestHeader("Content-Type", kwArgs.multipart ? ("multipart/form-data; boundary=" + this.multipartBoundary) :
(kwArgs.contentType || "application/x-www-form-urlencoded"));
try{
http.send(query);
}catch(e){
if(typeof http.abort == "function"){
http.abort();
}
doLoad(kwArgs, {status: 404}, url, query, useCache);
}
}else{
var tmpUrl = url;
if(query != "") {
tmpUrl += (tmpUrl.indexOf("?") > -1 ? "&" : "?") + query;
}
if(preventCache) {
tmpUrl += (dojo.string.endsWithAny(tmpUrl, "?", "&")
? "" : (tmpUrl.indexOf("?") > -1 ? "&" : "?")) + "dojo.preventCache=" + new Date().valueOf();
}
if (!kwArgs.user) {
http.open(kwArgs.method.toUpperCase(), tmpUrl, async);
}else{
http.open(kwArgs.method.toUpperCase(), tmpUrl, async, kwArgs.user, kwArgs.password);
}
setHeaders(http, kwArgs);
try {
http.send(null);
}catch(e) {
if(typeof http.abort == "function"){
http.abort();
}
doLoad(kwArgs, {status: 404}, url, query, useCache);
}
}
if( !async ) {
doLoad(kwArgs, http, url, query, useCache);
_this._blockAsync = false;
}
kwArgs.abort = function(){
try{// khtml doesent reset readyState on abort, need this workaround
http._aborted = true;
}catch(e){/*squelsh*/}
return http.abort();
}
return;
}