當前位置:
首頁 >
java ajax上传文件图片以json形式返回
發布時間:2025/5/22
41
豆豆
生活随笔
收集整理的這篇文章主要介紹了
java ajax上传文件图片以json形式返回
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jsp頁面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><base href="<%=basePath%>"><title>My JSP 'ajaxtext.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script></head><body><form action='Ajaxtext' method='post' enctype="multipart/form-data" id='form1'><input type="text" name="name"><input type="text" name="age"><input type="file" name="img"><button class="but" type="button">提交</button></form>></body><script>$(function(){$(".but").click(function(){var form= new FormData($("#form1")[0]);console.log(form);$.ajax({url:"Ajaxtext",type: 'POST',data:form,dataType: 'JSON',processData: false,contentType: false,success:function(da){console.log(da);alert(11);},error:function(err){alert("服務器錯誤")}})})})</script> </html>java頁面 上傳圖片的位置參考 https://blog.csdn.net/qq_43632766/article/details/90017859
注意需要下載
總結
以上是生活随笔為你收集整理的java ajax上传文件图片以json形式返回的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java日期时间的转化
- 下一篇: java生成验证码登录,生成验证码