Possible to upload file and parse the json result?

跟風遠走 提交于 2020-01-03 03:40:09

问题


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...

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>

The post will get a JSON response.


回答1:


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.

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



来源:https://stackoverflow.com/questions/4301799/possible-to-upload-file-and-parse-the-json-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!