Previous Projects/Goal-Bilby-master/SourceCode&WARfile/WebContent/scripts/main.js
// load the local file and sent it to server to convert it to JSON struture.
load the local file and sent it to server to convert it to JSON struture.
load the local file and sent it to server to convert it to JSON struture .
function uploadAndSubmit() {
	var form = document.forms["demoForm"];
	if (form["inputfile"].files.length > 0) {
		var file = form["inputfile"].files[0];
		var reader = new FileReader();
		reader.onloadstart = function () {
			console.log("onloadstart");
		};
		reader.onprogress = function (p) {
			console.log("onprogress");
		};
		reader.onload = function () {
			console.log("load complete");
		};
		reader.onloadend = function () {
			if (reader.error) {
				console.log(reader.error);
			} else {
				var xhr = new XMLHttpRequest();
				xhr.open(
					"POST",
					"/GoalModelEditor/XMLUpload?fileName=" + file.name
				);
				xhr.overrideMimeType("application/octet-stream");
				console.log(reader.result);
				xhr.send(reader.result);
				xhr.onreadystatechange = function () {
					if (xhr.readyState == 4) {
						if (xhr.status == 200) {
							console.log("upload complete");
							console.log("response: " + xhr.responseText);
							data = xhr.responseText;
							root = d3.hierarchy(JSON.parse(data));
							update(root);
							treeJSON2JointJSON();
						}
					}
				};
			}
		};
		reader.readAsBinaryString(file);
	} else {
		alert("Please choose a file.");
	}
}
function uploadAndSubmit ( ) { var form = document . forms [ "demoForm" ] ; if ( form [ "inputfile" ] . files . length > 0 ) { var file = form [ "inputfile" ] . files [ 0 ] ; var reader = new FileReader ( ) ; reader . onloadstart = function ( ) { console . log ( "onloadstart" ) ; } ; reader . onprogress = function ( p ) { console . log ( "onprogress" ) ; } ; reader . onload = function ( ) { console . log ( "load complete" ) ; } ; reader . onloadend = function ( ) { if ( reader . error ) { console . log ( reader . error ) ; } else { var xhr = new XMLHttpRequest ( ) ; xhr . open ( "POST" , "/GoalModelEditor/XMLUpload?fileName=" + file . name ) ; xhr . overrideMimeType ( "application/octet-stream" ) ; console . log ( reader . result ) ; xhr . send ( reader . result ) ; xhr . onreadystatechange = function ( ) { if ( xhr . readyState == 4 ) { if ( xhr . status == 200 ) { console . log ( "upload complete" ) ; console . log ( "response: " + xhr . responseText ) ; data = xhr . responseText ; root = d3 . hierarchy ( JSON . parse ( data ) ) ; update ( root ) ; treeJSON2JointJSON ( ) ; } } } ; } } ; reader . readAsBinaryString ( file ) ; } else { alert ( "Please choose a file." ) ; } }
load the local file and sent it to server to convert it to JSON struture.
load the local file and sent it to server to convert it to JSON struture .
// try sending // create xml object to sent request. /* method */ /* target url */ /* , async, default to true */ // Initalize function