可以上传文件并解析json结果吗? [英] Possible to upload file and parse the json result?

查看:238
本文介绍了可以上传文件并解析json结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于上传文件的表单和服务器端的CGI程序来处理上传的文件。该文件将重命名为我想传递回客户端的其他文件名,我想使用JSON返回结果,但浏览器总是提示我将returnnd文档保存到文件中...

I have a form that is used to upload the file and a CGI program in the server side to process the uploaded file. The file will be renamed to a different file name that I want to pass back to the client, I want to use JSON to return the result, but the browser always prompts me to save the returnd document to a file...

结论:我想上传一个文件并从HTTP响应中解析它以获取服务器端生成的新文件名。

Conclusion: I want to upload a file and from the HTTP response I want to parse it to get the new filename generated by server side.

        <form action="/a.bc?cmd=upload&user_name=binc2&size=100&type=normal" method="post" enctype="multipart/form-data">
                <input type="file" name="image">
                <input type="submit" value="Submit" />
                <input type="text" value="ade75596e1d9a04d4ae0c1e81aa8fcf0" name="key" />
        </form>

该帖子将获得JSON回复。

The post will get a JSON response.

推荐答案

听起来你实际上并没有发出ajax请求...因为标题是(并且应该是) application / json 。如果您没有执行ajax请求或使用其他脚本填充响应,则没有理由使用json,jsut渲染任何您想要呈现的内容。

It sounds like youre not actually making an ajax request... youre being prompted to download because the header is (and should be) application/json. If youre not executing an ajax request or consumign the response with some other script then there is no reason to use json, jsut render whatever you want rendered.

此外,您无法上传直接用ajax文件。如果您需要这样做,请搜索各种技术的ajax upload。

Also you cant upload files directly with ajax. if you need to do this, do a search for "ajax upload" for various techniques.

这篇关于可以上传文件并解析json结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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