上传图像并使用ajax在同一页面中显示图像

时间:2014-01-30 07:27:14

标签: javascript php jquery ajax

以下是我的代码。但是在提交之后它无法工作我需要调用ajax以便我可以显示我上传的图像

php code

 <?php

       if(isset($_POST['act']))
             $act = $_POST['act'];

         if($_FILES['photoimg']!='')
         {
            //here I am uploading image in one folder and the name in table
         }
        switch($act)
           {
               case "getImageName"       : print("hello");
                                           exit;
                                           break;                      

           }
     ?>

HTML代码

 <form id="imageform" method="post" enctype="multipart/form-data" action="">
          <input type="file" name="photoimg" id="photoimg"/>  
          <span id="preview1"></span>  
 </form>

Javascript代码

<script>
 $(document).ready(function()
{
 $('#photoimg').click(function()    
    {

            agentId       = $('#agentID').val();
            propertyID    = $('#propertyID').val();
            url = "";

            $.post(
                url,{
                     "act"  :"getImageName",
                     "agentID" : agentId,
                     "PropertyID" : propertyID
                    },
                function(data)
                {
                    alert(data);
                    $('#preview1').html(data);

                },
                "html"
                );


    });
});
</script>

0 个答案:

没有答案
相关问题