小编Sed*_*şar的帖子

使用Ajax XmlHttpRequest上传文件

嗨,我正在尝试使用此代码发送带有xmlhttprequest的文件.

<script>
    var url= "http://localhost:80/....";
    $(document).ready(function(){
        document.getElementById('upload').addEventListener('change', function(e) {
            var file = this.files[0];
            var xhr = new XMLHttpRequest();
            xhr.file = file; // not necessary if you create scopes like this
            xhr.addEventListener('progress', function(e) {
                var done = e.position || e.loaded, total = e.totalSize || e.total;
                console.log('xhr progress: ' + (Math.floor(done/total*1000)/10) + '%');
            }, false);
            if ( xhr.upload ) {
                xhr.upload.onprogress = function(e) {
                    var done = e.position || e.loaded, total = e.totalSize || e.total;
                    console.log('xhr.upload progress: ' + done + ' …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery file-upload xmlhttprequest

57
推荐指数
1
解决办法
12万
查看次数

从Resteasy服务器返回文件

嗨,我想从resteasy服务器返回一个文件.为此,我在客户端有一个链接,它使用ajax调用rest服务.我想在休息服务中返回该文件.我尝试了这两个代码块,但两个都没有按照我的要求工作.

    @POST
    @Path("/exportContacts")
    public Response exportContacts(@Context HttpServletRequest request, @QueryParam("alt") String alt) throws  IOException {

            String sb = "Sedat BaSAR";
            byte[] outputByte = sb.getBytes();


    return Response
            .ok(outputByte, MediaType.APPLICATION_OCTET_STREAM)
            .header("content-disposition","attachment; filename = temp.csv")
            .build();
    }
Run Code Online (Sandbox Code Playgroud)

.

@POST
@Path("/exportContacts")
public Response exportContacts(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("alt") String alt) throws IOException {

    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment;filename=temp.csv");
    ServletOutputStream out = response.getOutputStream();
    try {

        StringBuilder sb = new StringBuilder("Sedat BaSAR");

        InputStream in =
                new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
        byte[] outputByte = sb.getBytes();
        //copy binary contect to output stream …
Run Code Online (Sandbox Code Playgroud)

java rest file-io resteasy java-io

10
推荐指数
1
解决办法
1万
查看次数

超出div时禁用鼠标单击

嗨,我有一个表格的div.我希望当鼠标不在div时禁用点击事件.所以我尝试了这个,但它不工作的div仍然是可点击的.任何的想法??

var flag = false;
$("#foo").live("mouseenter",function(){
    flag = true;
}).live("mouseleave",function(){
    flag = false;
})

$(document).click(function(){
    if(!flag)
         return false;
});
Run Code Online (Sandbox Code Playgroud)

jquery

8
推荐指数
1
解决办法
6839
查看次数