All pastes #978454 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-09 15:58 UTC
rendered paste body
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser is too old!\nIt's a good moment to upgrade it!");
	}
}

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();

//Called from submit button of the form for uploading...
//Starts the AJAX request.
//svg is the svg filename which is sent in the url
//jpg is the jpg filename which will be generated and sent in the url
function searchSuggest(svg, jpg, jpgfiletorefresh) {
	var url    = 'prog/uploadimage/call_rasteriser.php';
	var params = 'svg=' +  encodeURIComponent(svg) + '&jpg='+  encodeURIComponent(jpg);
	searchReq.open("POST", url, true);
		searchReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		searchReq.setRequestHeader("Content-length", params.length);
		searchReq.setRequestHeader("Connection", "close");
		searchReq.onreadystatechange = function() {//Call a function when the state changes.
			if(searchReq.readyState == 4 && searchReq.status == 200) {
				handleSearchSuggest(svg,jpg, jpgfiletorefresh);
				//alert(searchReq.responseText);
			}
		}
	searchReq.send(params);
}

//Called when the AJAX response is returned.
function handleSearchSuggest(svg,jpg, jpgfiletorefresh) {
	var svg = svg;
	var jpg = jpg;
	var jpgfiletorefresh = jpgfiletorefresh;
	if (searchReq.readyState == 4) {
		//alert(document.getElementById('preview').getAttribute('src'));
		//window.location.reload();
		var ss = document.getElementById('preview');
		ss.src = jpgfiletorefresh;
		//alert(jpg);
	}
}