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>