如何提交文件而不将其发布到服务器?
我希望我的用户能够将图片上传到我的服务器,并且无需他们切换页面即可在上传完成后将该图像弹回该网站上的 div。
这是“更改您的个人资料图片”页面。我需要取回图片,以便我可以调用 jCrop jquery 库,以便他们可以根据自己的喜好裁剪图片。
这是我到目前为止所做的:
@{
ViewBag.Title = "Profile Picture";
}
<h1>Please choose your new profile picture.</h1>
<input type="file" name="file" />
<input type="submit" value="OK" />
如果我放入 @using BeginForm
,表单将被发回,并且页面将加载到新的位置。我不想要这种行为。如何在不重新加载的情况下使用 AJAX 执行此操作?
I'd like my users to be able to upload a picture to my server and without having them switch pages have that image bounced back to a div on that site once the upload has finished.
This is for a "Change your profile picture" page. I need to get the picture back so I can invoke the jCrop jquery library on it so they can crop the picture to their liking.
Here's what I have so far:
@{
ViewBag.Title = "Profile Picture";
}
<h1>Please choose your new profile picture.</h1>
<input type="file" name="file" />
<input type="submit" value="OK" />
If I put in the @using BeginForm
the form is posted back and the page loads somewhere new. I don't want this behavior. How do I do this with AJAX without reloading?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您的浏览器支持文件 API,否则您无法通过 ajax 提交文件。 https://developer.mozilla.org/en/using_files_from_web_applications
您可以创建一个 iframe 并使用提交您的图像。
如何异步上传文件?
You can't submit a file via ajax unless your browser supports the file API. https://developer.mozilla.org/en/using_files_from_web_applications
You can create an iframe and use that to submit your image.
How can I upload files asynchronously?