0

我有这个将文本插入数据库的鳕鱼,但我需要将带有文本的图像插入数据库。

我的代码 ajax 像:-

function AddComment(){
     var text=$("#text").val();
     $.ajax({
           type:"post",
           url:"application/controllers/process.php",
           data:"text="+text+"&action=add",
           success:function(data){
                      showComment();              
                   }
     });
 }

我的表格:-

<form>
          <input id="inputUpProfile" name="inputUpProfile" class="inputUpProfile hidefile" type="file" onchange="readURL(this)"/>
          <img id="blah" src="#" width="100" height="100" style="display:none" />

          <textarea name="post" id="text" rows="3" cols="40" onkeyup="textAreaAdjust(this)" style="overflow:hidden"></textarea>

          <ol class="controls clearfix">
              <input type="button" id="sent" onclick="AddComment();" class="uibutton confirmb" value="Send"> 
</form>
4

1 回答 1

0

要使用 Ajax 上传图像,您需要使用 iFrame、flash 插件或类似的东西。使用 iFrame,其概念是您在页面的某处有一个带有 ID 的 iFrame(不可见)。您将表单的目标属性指向它,然后在 iFrame 的结果页面中调用父窗口的 javascript 中的一个函数,该函数会触发主窗口中的结果。它相当简单,不需要大型插件或乱七八糟。

这在堆栈上有大量记录,因此请进行一些搜索。 https://stackoverflow.com/search?q=php+ajax+jquery+upload+image+with+iframe

于 2013-10-04T00:05:16.393 回答