Ever wanted to upload files like in GMAIL, without reloading the page? Now you can. Cross browser method to upload files (submit forms) using AJAX in only 1Kb of code.
First include this library at the top of your code (you can find the library in the source code section of this page).
Do it in <head> tag. After loading the library you can write your code.
Source code for index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"lang="en-US"> <head> <metahttp-equiv="Content-Type"content="text/html; charset=UTF-8" /> <title>Iframe Ajax</title> <scripttype="text/javascript"src="webtoolkit.aim.js"></script> <scripttype="text/javascript">
function startCallback() {
// make something useful before submit (onStart)
return true;
}
function completeCallback(response) {
// make something useful after (onComplete)
document.getElementById('nr').innerHTML = parseInt(document.getElementById('nr').innerHTML) + 1;
document.getElementById('r').innerHTML = response;
} </script> </head>
loaded : function(id){ var i = document.getElementById(id); if(i.contentDocument){ var d = i.contentDocument; }elseif(i.contentWindow){ var d = i.contentWindow.document; }else{ var d = window.frames[id].document; } if(d.location.href == "about:blank"){ return; }