Call a particular PHP Function In same page using AJAX -
i creating widget using php, jquery , ajax can upload , crop image. when select image, , submit form. following code executed, uploads image:
<?php $valid_formats = array("jpg", "png", "gif", "bmp"); if(isset($_post['submit'])) { $name = $_files['photoimg']['name']; $size = $_files['photoimg']['size']; if(strlen($name)) { list($txt, $ext) = explode(".", $name); if(in_array($ext,$valid_formats) && $size<(1024*1024)) { $actual_image_name = time().substr($txt, 5).".".$ext; $tmp = $_files['photoimg']['tmp_name']; if(move_uploaded_file($tmp, $path.$actual_image_name)) { $image="<img src='uploads/".$actual_image_name."' id=\"photo\" style='max-width:500px' >"; } else echo "failed"; } else echo "invalid file formats..!"; } else echo "please select image..!"; } ?> while submitting form, page getting refreshed. want without page refresh.
suppose if put above php code in php function, without using
if(isset($_post['submit']))
then, there way, call php function using ajax.
thanks in advance....
actually, looking can submit php form via ajax image selected , upload image. found code,
$('#photoimg').live('change', function(){ $("#preview").html(''); $("#imageform").ajaxform({ target: '#preview' }).submit(); }); here, photoimg id of input type file, imageform id of form, , preview id of div, preview going displayed. when file selected, change event fired , form submitted. can refer this.
Comments
Post a Comment