第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

現(xiàn)在就只能把textarea里的信息post到后端,圖片上傳不了,該怎么解決呢?

現(xiàn)在就只能把textarea里的信息post到后端,圖片上傳不了,該怎么解決呢?

qq_遁去的一_1 2023-04-16 18:14:27
form里既有數(shù)據(jù)也有圖片上傳js代碼: <script type="text/javascript">       $(document).ready(function(){       //DOM的onload事件處理函數(shù)        $("#send").click(function(){   //當(dāng)按鈕button被點(diǎn)擊時(shí)的處理函數(shù)         postdata();                   //button被點(diǎn)擊時(shí)執(zhí)行postdata函數(shù)                             });     });    function postdata(){            //提交數(shù)據(jù)函數(shù)        $.ajax({                     //調(diào)用jquery的ajax方法          type: "post",              //設(shè)置ajax方法提交數(shù)據(jù)的形式          url: "sendmes.php",             //把數(shù)據(jù)提交到sendmes.php          dataType: "json",//返回?cái)?shù)據(jù)類型        data: $("#send_form").serialize(),               });     }         </script>html form:<form id="send_form" enctype="multipart/form-data"> <textarea name="message" id="msg"></textarea> <input type="file" name="upload" id="upload"> <input type="submit" class="send" id="send" value="發(fā)布"> </form>
查看完整描述

2 回答

?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊

比如 upload.php?text=你要加的文本。

		<script type="text/javascript">   			function inputFileChange(){
   				$.ajaxFileUpload({
	                url:'<%=basePath %>file/uploadtempimage.action',//用于文件上傳的服務(wù)器端請(qǐng)求地址
	                secureuri:false,//一般設(shè)置為false
	                fileElementId:'photofile',//文件上傳空間的id屬性  <input type="file" id="file" name="file" />
	                dataType: 'json',//返回值類型 一般設(shè)置為json
	                success: function (data,status)  //服務(wù)器成功響應(yīng)處理函數(shù)
	                {	
	                    $("#testImg").attr("src",data.src);  //后臺(tái)返回的JSON格式字符串,src 是上次圖片的服務(wù)器地址
	                },
                    error: function (data, status, e) {  
  					      alert(e);  
			  		}
			  	})
			  	$("#photofile").replaceWith('<input type="file" name="file" onchange="inputFileChange()" id="photofile" value="" />');  // 更換input 標(biāo)簽, 如果用Button提交可以不要,如果 是 onchange="inputFileChange()" 就一定要替換
   			}
	   		</script>

我的事jsp的
希望對(duì)你有用,以前學(xué)習(xí)的時(shí)候用到這個(gè),給你翻出來了


查看完整回答
反對(duì) 回復(fù) 2023-04-20
?
慕桂英4014372

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊

不如你看看 $('#send_form').serialize() 能得到啥?

除非使用HTML5的File API,否則ajax沒法直接POST文件的。


查看完整回答
反對(duì) 回復(fù) 2023-04-20
  • 2 回答
  • 0 關(guān)注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)