duanhui1869 2015-07-19 12:11
浏览 19

在jquery中使用jquery上传的img并将其传递给php

Hi I'm trying to create meme generator. I have a jquery code that uploads an image without writing on disk.

    <table>
        <tr>
            <td colspan="2">
                <form id="form1" runat="server">
                    <input type='file' id="imgInp" />
                    <img id="gag" src="#" alt="your image" />
                </form>
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" placeholder="Upper Text" id="upperTextbox"/> 
            </td>
            <td>
                <input type="text" placeholder="Lower Text" id="lowerTextbox"/> 
            </td>
        </tr>
        <tr>
            <td><p style="font-size:14px;color:#CCC;">Image updates on textbox focus out</p></td>
        </tr>
    </table> 

   <script>
   function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
           iurl = $('#gag').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#imgInp").change(function(){
    readURL(this);
});
</script>

I'm trying to use uploaded img in another jquery script which should pass the img to php script with ajax but I don't know how to grap the image and pass into this? I tried var iurl = $('#gag').attr('src'); but this doesn't even work. How can I do this? thanks.

<script>
var iurl = $('#gag').attr('src');

$('#lowerTextbox').focusout(function(){
    if($.trim($(this).val()) != "")
    {
        SendAjaxRequest($('#upperTextbox').val(),$(this).val(),"lower");
    }
});
$('#upperTextbox').focusout(function(){
    if($.trim($(this).val()) != "")
    {
        SendAjaxRequest($(this).val(),$('#lowerTextbox').val(),"upper");
    }
});


function SendAjaxRequest(umsg,dmsg,iurl,type)
{
    $.ajax({
        url: 'generator.php',
        type: 'POST',
        data: { upmsg : umsg, downmsg : dmsg, imgurl : iurl, mguposition: type },
        success:function(e)
        {
            $('#error').html(e);
            $('#gag').attr('src',e);
        }
    });
}
</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作