jug Posted January 26, 2011 Share Posted January 26, 2011 Hi, Im trying to create my own 'AJAX' image uploader which posts form data in a hidden iframe on the same page however I cannot get it to work without the page refreshing. The code is simple I hope I have made just a stupid error. HTML File <form id="upload_img_form" method="post" action="" onsubmit="uploadStart();" enctype="multipart/form-data"> <input type="text" name="imgname" id="imgname" value="" /> <input type="submit" name="imgbutton" id="imgbutton" value="Upload" /> <iframe id="upload_iframe" name="upload_iframe"></iframe> </form> JS File function uploadStart () { document.getElementById('img_form').target = 'upload_iframe'; document.getElementById('upload_iframe').src = 'upload.php'; $('#upload_iframe').load(function () { uploadComplete(); }); return false; } function uploadComplete () { var responseMessage = $('#upload_iframe').contents().text(); alert(responseMessage); } PHP File <?php echo $_POST['imgname']; ?> For now all I need is for the script to alert out the name of the text input without the page refreshing. From there I reckon I can sort the rest. If anyone could help me out here, itll be greatly appreciated. Thanks in advance Quote Link to comment Share on other sites More sharing options...
The Letter E Posted February 1, 2011 Share Posted February 1, 2011 You can try something like this... HTML: <html> <head> <title>...</title> <body> <a href="whatever.php?alert=myAlert" target="myIframe">Post Alert!</a> <iframe src="whatever.php" name="myIframe" style="do your styling"></iframe> </body> </html> IFRAME: <html> <head> <title>...</title> </head> <?php $alert = $_GET['alert']; echo '<body onload="alert(\''.$alert.'\');">'; ?> </body> </html> You can obviously elaborate on this method, create functions Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 4, 2011 Share Posted February 4, 2011 Check this video out. Came across it just today whilst trying to learn some AJAX. Turns out this isn't using ajax, however it is using iFrames, as you're requesting. http://www.youtube.com/watch?v=TiV5vCar_cI&feature=mfu_in_order&list=UL Denno Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.