栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Ajax将图片传递到PHP

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Ajax将图片传递到PHP

我在我的一个项目中做到了这一点,下面的代码对我有用。请根据需要对代码进行必要的修改。

我的表单按钮:

 <form name="upload_img" enctype="multipart/form-data" id="upload_img"><input type="file"  id="upload-image" name="upload-image"></input><button id="upload_image" type="button">Save</button></form>

我的JQuery / Ajax:

$('#upload_image').click(function(){    var form = new FormData(document.getElementById('upload_img'));    //append files    var file = document.getElementById('upload-image').files[0];    if (file) {form.append('upload-image', file);    }    $.ajax({        type: "POST",        url: "URL",        data: form,          cache: false,        contentType: false, //must, tell jQuery not to process the data        processdata: false,        //data: $("#upload_img").serialize(),        success: function(data)        { if(data == 1)     $('#img_msg').html("Image Uploaded Successfully"); else     $('#img_msg').html("Error While Image Uploading");        }    });    //alert('names');});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413485.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号