如何为特定网页启用UniversalXPConnect? [英] How do I enable UniversalXPConnect for a particular web page?

查看:68
本文介绍了如何为特定网页启用UniversalXPConnect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试各种Web服务,这些服务是将上传文件作为正文内容的帖子.为此,我想使用ajax调用进行快速测试.我发现以下页面描述了如何执行此操作: http://www.captain.at/ajax-file-upload.php但是,它要求页面在firefox中具有"UniversalXPConnect"特权.

I need to test various web services which are posts that take an uploaded file as the content of the body. To do this I'd like to do quick tests using ajax call. I found the following page which describes how to do this: http://www.captain.at/ajax-file-upload.php However, it requires that the page have "UniversalXPConnect" privileges in firefox.

如何启用该特权?我尝试编辑prefs.js并添加:

How do I enable that privilege? I tried editing prefs.js and adding:

user_pref("capability.principal.foo.id", "http://localhost:8080/access/index.html");
user_pref("capability.principal.foo.granted", "UniversalXPConnect");

应该可以访问页面 http://localhost:8080/access/index.html .但是,它似乎不起作用.

which should give access to the page http://localhost:8080/access/index.html. But, it doesn't seem to work.

推荐答案

在panzi的答案上,您可以使用FormData对象以非常简单的方式使用Ajax发送文件:

Improving on panzi's answer, you can use the FormData object to send files with Ajax in a very simple manner:

<html>
<head>
<title>HTML5 File API</title>
</head>
<script type="text/javascript">
// <!--
// See: https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects
function upload() {
    var uploadRequest = new XMLHttpRequest,
        uploadForm = document.getElementById('file_upload');

    function transferProgress(progressEvent) {
    /*Executes For each update of the progress of the Ajax transfer.*/
        // show progress bar or something....
    }
    function transferComplete() {
    /*Executes when the transfer is complete.*/
        //Do something like show a nice message...
    }
    function transferFailed() {
    /*Executes when the transfer fails.*/
        alert('Upload failed!');
    }
    function transferCanceled() {
    /*Executes when the transfer is canceled.*/
        alert('Upload canceled!');
    }

    uploadRequest.upload.addEventListener('progress', transferProgress, false);
    //uploadRequest.upload.addEventListener('load', transferComplete, false); // transfer complete, but this doesn't mean a response from the server has been received.
    uploadRequest.addEventListener('load', transferComplete, false); // ajax request complete, response from the server has been received and all has been processed.
    uploadRequest.upload.addEventListener('error', transferFailed, false);
    uploadRequest.upload.addEventListener('abort', transferCanceled, false);

    uploadRequest.open('POST', action, true);
    uploadRequest.send(new FormData(uploadForm));
}
// -->
</script>
<body>
<form id="file_upload" enctype="multipart/form-data">
    <input type="text" id="text" value="blah blah blah"/>
    <input type="file" onchange="upload();"/>
</form>
</body>
</html>

这篇关于如何为特定网页启用UniversalXPConnect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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