显示图像从另一个php文件,通过AJAX和jQuery上传后 [英] Display the image after uploading it from another php file through ajax and jquery

查看:374
本文介绍了显示图像从另一个php文件,通过AJAX和jQuery上传后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在加载页面时,在SRC指定的图片displayed.When用户点击窗体上上传的图像,一切工作正常,除了在网页上的图像不会改变。 这是因为当用户点击窗体上上传的图像,他是针对PHP文件2,但在那里,没有人要求改变的PHP文件1.图像我怎样才能做到这一点(使用AJAX和jQuery)?

When the page is loaded, the image specified in src is displayed.When a user clicks on the form to upload the image,everything works fine except the image on the page does not change. It is because when the user clicks on the form to upload the image, he is directed to php file 2 but from there there is no request to change the image in php file 1. How can I achieve this (using ajax and jquery)?

推荐答案

试试这个code。这是核心

Try this code. This is the core.

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
            $('#imgInp').on('change', function() {
            readPath(this);
            });
            });

            function readPath(input) {
            if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
          $('#blah').attr('src', e.target.result);
            }
          reader.readAsDataURL(input.files[0]);
                }
            }
        </script>
    </head>
    <body>
<form id="form1">
    <input type='file' id="imgInp" />
    <img id="blah" src="#" width="500px" height="200px" alt="your image" />
</form>

    </body> 
</html>

这篇关于显示图像从另一个php文件,通过AJAX和jQuery上传后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆