簡體   English   中英

我如何通過Ajax和PHP上傳圖像

[英]How can i upload image by ajax and php

我有將文本插入數據庫的鱈魚,但我需要將帶有文本的圖像插入數據庫。

我的代碼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>

要使用Ajax上傳圖像,您需要使用iFrame,Flash插件或類似的工具。 使用iFrame,其概念是在頁面上某處具有ID的iFrame(不可見)。 您將表單的target屬性指向該屬性,然后在iFrame的結果頁面中調用父窗口javascript中的函數,該函數會在主窗口中觸發結果。 這是相當簡單的,不需要大型插件或太多的麻煩。

這在堆棧上有大量記錄,因此請進行一些搜索。 https://stackoverflow.com/search?q=php+ajax+jquery+upload+image+with+iframe

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM