-
Notifications
You must be signed in to change notification settings - Fork 1
/
cgi-test.html
96 lines (90 loc) · 3.05 KB
/
cgi-test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
function init() {
$("#testBtn").button().on("click", function() {
ajaxFunction();
});
//some examination of file when you choose a new one
$(':file').change(function(){
var file = this.files[0];
var name = file.name;
var size = file.size;
var type = file.type;
console.log(name);
});
$(':button').click(function(){
var formData = new FormData($('form')[0]);
$.ajax({
url: 'http://pearl.vasc.ri.cmu.edu/cgi-bin/upload.py', //Server script to process data
type: 'POST',
xhr: function() { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // Check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
}
return myXhr;
},
//Ajax events
//beforeSend: beforeSendHandler,
success: function(data){
console.log("Success! Data: " + data);
},
//error: errorHandler,
// Form data
data: formData,
//Options to tell jQuery not to process data or worry about content-type.
cache: false,
contentType: false,
processData: false
});
});
function progressHandlingFunction(e){
if(e.lengthComputable){
$('progress').attr({value:e.loaded,max:e.total});
}
}
}
function ajaxFunction() {
$.get( "http://pearl.vasc.ri.cmu.edu/cgi-bin/time.py").done(function( data ) {
document.myForm.time.value = data;
});
// var xmlHttp;
// try { //Firefox,Opera 8.0+ safari
// xmlHttp = new XMLHttpRequest();
// } catch (e) { //Inter Explorer
// try {
// xmlHttp = new ActiveXObject("Msxm12.XMLHTTP");
// } catch(e) {
// try {
// xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
// } catch (e) {
// alert("Your browser does not support AJAX!");
// return false;
// }
// }
// }
// xmlHttp.onreadystatechange = function() {
// //console.log("garbage");
// if(xmlHttp.readyState == 4) {
// console.log(xmlHttp.responseText);
// document.myForm.time.value = xmlHttp.responseText;
// }
// }
// xmlHttp.open("Get", "http://pearl.vasc.ri.cmu.edu/cgi-bin/time.py", true);
// xmlHttp.send(null);
}
$(init);
</script>
<!--<button id="testBtn">test</button>
<form name="myForm"> Name: <input type="text" name="username" /> Time: <input type="text" name="time" /> </form> -->
<form enctype="multipart/form-data">
<input name="file" type="file" />
<input type="button" value="Upload" />
</form>
<progress></progress>
</body>
</html>