Subversion Repositories SmartDukaan

Rev

Rev 23405 | Rev 23500 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23405 Rev 23494
Line 122... Line 122...
122
 
122
 
123
function doAjaxDownload(urlString, httpType, data, fileName){
123
function doAjaxDownload(urlString, httpType, data, fileName){
124
	xhttp = new XMLHttpRequest();
124
	xhttp = new XMLHttpRequest();
125
	xhttp.onreadystatechange = function() {
125
	xhttp.onreadystatechange = function() {
126
	    var a;
126
	    var a;
-
 
127
	    if(xhttp.readyState === 2){
-
 
128
	    	if(xhttp.status == 200){
-
 
129
	    		xhttp.responseType = "blob";
-
 
130
            } else {
-
 
131
                xhttp.responseType = "text";
-
 
132
            }
127
	    if (xhttp.readyState === 4 && xhttp.status === 200) {
133
	    }else if (xhttp.readyState === 4 && xhttp.status === 200) {
128
	        // Trick for making downloadable link
134
	        // Trick for making downloadable link
129
	        a = document.createElement('a');
135
	        a = document.createElement('a');
130
	        a.href = window.URL.createObjectURL(xhttp.response);
136
	        a.href = window.URL.createObjectURL(xhttp.response);
131
	        // Give filename you wish to download
137
	        // Give filename you wish to download
132
	        a.download = fileName;
138
	        a.download = fileName;
133
	        a.style.display = 'none';
139
	        a.style.display = 'none';
134
	        document.body.appendChild(a);
140
	        document.body.appendChild(a);
135
	        a.click();
141
	        a.click();
136
	    }
-
 
137
	    if(xhttp.readyState == 4 && xhttp.status === 400){
142
	    }else if(xhttp.readyState == 4 && xhttp.status === 400){
138
	    		badRequestAlert(xhttp.responseText);
143
    		badRequestAlert(xhttp);
139
	    }
-
 
140
	    if(xhttp.readyState == 4 && xhttp.status === 500){
144
	    }else if(xhttp.readyState == 4 && xhttp.status === 500){
141
	    		internalServerErrorAlert(xhttp.responseText);
145
	    	internalServerErrorAlert(xhttp);
142
	    }
146
	    }
143
	};
147
	};
144
	// Post data to URL which handles post request
148
	// Post data to URL which handles post request
145
	xhttp.open(httpType, urlString);
149
	xhttp.open(httpType, urlString);
146
	if(httpType == "POST"){
150
	if(httpType == "POST"){
147
		xhttp.setRequestHeader("Content-Type", "application/json");
151
		xhttp.setRequestHeader("Content-Type", "application/json");
148
	}
152
	}
149
	// You should set responseType as blob for binary responses
153
	// You should set responseType as blob for binary responses
150
	xhttp.responseType = 'blob';
154
	//xhttp.responseType = 'blob';
151
	xhttp.send(data);
155
	xhttp.send(data);
152
}
156
}
153
 
157
 
154
 
158
 
155
function numberToComma(x) {
159
function numberToComma(x) {