View Single Post
Old 08-29-2012, 03:59 PM   PM User | #1
unicorn6684
New to the CF scene

 
Join Date: Aug 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
unicorn6684 is an unknown quantity at this point
sycronize ajax with progress info

I'm tryin to upadte lots of data using ajax and update the info box during the process. but when i start the process the page get stuck so only the final messege apears.

the code:
Code:
function ExecutePage(url)
{
	try
	{
		// for explorer
		if(url.indexOf("?") < 0) 	url += "?rnd=" + Math.random();
		else						url += "&rnd=" + Math.random();
		
		var xmlhttp;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.open("GET",url,false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send();
		if(xmlhttp.status == 404) return "ajax not found file '" + url + "'";
		else return xmlhttp.responseText;
	}
	catch (err) {alert(err.description); return "error";}
}
function start_import()
{
	var progress_box = document.getElementById("progress_box");
	
	var groups = ExecutePage("template/import/get_main_groups.php");
	progress_box.innerHTML = "ייבוא קטגוריות: ";
	
	groups = groups.split("#");
	for(var i = 0; i < groups.length; i++)
	{
		//alert(i);
		var percent = Math.round(100*i/groups.length);
		progress_box.innerHTML = "ייבוא קטגוריות: " + percent + "%";
		
		//alert(i);
		var id_name = groups[i].split(",");
		ExecutePage("template/import/add_group.php?id=" + id_name[0] + "&name=" + id_name[1]);
	
	}
	progress_box.innerHTML = "ייבוא קטגוריות: הושלם";
}
unicorn6684 is offline   Reply With Quote