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

Javascript 上传图像并使用ajax在同一页面中显示图像,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,下面是我的代码。但是在提交了之后它就不起作用了,因为我需要调用一个ajax,这样我才能显示我上传的图像 php代码 <?php if(isset($_POST['act'])) $act = $_POST['act']; if($_FILES['photoimg']!='') { //here I am uploading image in one folder and the nam

下面是我的代码。但是在提交了之后它就不起作用了,因为我需要调用一个ajax,这样我才能显示我上传的图像

php代码

 <?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>

$(文档).ready(函数()
{
$('#photoimg')。单击(函数()
{
agentId=$('#agentId').val();
propertyID=$('#propertyID').val();
url=“”;
美元邮政(
网址{
“act”:“getImageName”,
“agentID”:agentID,
“PropertyID”:PropertyID
},
功能(数据)
{
警报(数据);
$('#preview1').html(数据);
},
“html”
);
});
});

您应该查看HTML5上传程序,例如Jquery文件上传。jQuery文件上传提供了对IE8和IE7的支持。不记得了。该支持是完整功能的一个子集,但它将实现您上面描述的功能。如果您想手动实现此功能,我认为您需要从iFrame显示上载程序。忘了我是如何实现的,但我相信你可以通过谷歌搜索找到实现。谢谢你的评论