使用JSON + AJAX上传文件? [英] file upload with JSON+AJAX?

查看:589
本文介绍了使用JSON + AJAX上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想转换一个目前使用传统

CGI序列的表单(即与表单相关的操作发送一个POST

请求服务器端CGI脚本)使用AJAX向远程Web服务发送

a JSON编码的请求。


绊脚石阻止我遇到的是

中的一个输入表单是文件上传元素,我不知道如何将
包括在内来自JSON有效负载中指定文件的数据。

有办法吗?


TIA!


Kynn

-

注意:在我的地址中,第一个时期之前的所有内容都是向后的;

和最后一个时期以及之后的所有内容都应该被丢弃。

解决方案

5月8日上午12:14,kj< so ... @ 987jk.com.invalidwrote:


我无法弄清楚如何将
包含来自JSON有效负载中指定文件的数据。

有办法做到这一点吗?



编号XHR不允许本地文件访问,因此对于文件上传,你需要使用传统表格。
必须使用传统表格。 />


VK写道:


5月8日上午12:14,kj< so ... @ 987jk .com.invalidwrote:


>我无法弄清楚如何在JSON有效载荷中包含指定文件中的数据。有没有办法做到这一点?



编号XHR不允许本地文件访问,



它在本地运行时执行。


因此,对于文件上传,您必须使用传统表单。



正确。

PointedEars

-

现实主义:HTML 4.01严格

福音传播:XHTML 1.0严格

疯狂:XHTML 1.1作为应用程序/ xhtml + xml

- Bjoern Hoehrmann


Thomas''PointedEars''Lahn写道:


VK写道:


> 5月8日上午12:14,kj< so ... @ 987jk.com.invalidwrote:


>>我可以'弄清楚如何在JSON有效负载中包含指定文件中的数据。有没有办法做到这一点?


No. XHR不允许本地文件访问,



它在本地运行时执行。



在通过HTTP运行时也会执行,并且授予所需的权限,

或用完沙箱时。


PointedEars

-

使用任何版本的Microsoft Frontpage创建您的网站。

(这赢了不要让人们查看你的来源,但是没有人会想要偷走它。)

- 来自< http://www.vortex-webdesign .com / help / hidesource.htm>



I would like to convert a form that currently uses the traditional
CGI sequence (i.e. the action associated with the form sends a POST
request to a server-side CGI script) to one that uses AJAX to send
a JSON-encoded request to a remote web service.

The stumbling block I''m running into is that one of the inputs in
the form is a file upload element, and I can''t figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?

TIA!

Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.

解决方案

On May 8, 12:14 am, kj <so...@987jk.com.invalidwrote:

I can''t figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?

No. XHR doesn''t allow local file access, so for the file upload you
have to use traditional forms.


VK wrote:

On May 8, 12:14 am, kj <so...@987jk.com.invalidwrote:

>I can''t figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?


No. XHR doesn''t allow local file access,

It does when running locally.

so for the file upload you have to use traditional forms.

Correct.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


Thomas ''PointedEars'' Lahn wrote:

VK wrote:

>On May 8, 12:14 am, kj <so...@987jk.com.invalidwrote:

>>I can''t figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?

No. XHR doesn''t allow local file access,


It does when running locally.

It also does when running via HTTP, and the required privileges are granted,
or when running out of the sandbox.

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won''t prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>


这篇关于使用JSON + AJAX上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆