我正在寻找从 Firefox 扩展向服务器上的 PHP 脚本发出 HTTP POST 请求并获取 JSON 作为返回。我希望在一个请求中发送到服务器的理想数据量对于 GET 请求来说太大了(由于实际的 URL 长度限制)。因此,我不能将 JSONP 用于 GET 请求。
是否可以访问任何 native Firefox 浏览器组件以向服务器发出 POST 请求,或者必须使用 XMLHttpRequest? (此扩展正在为 Firefox 4 开发。)
最佳答案
来自您的评论:
There are origin restrictions when performing cross-domain requests. JSONP is generally the solution for doing requests over different domains, but it is limited in that it is a GET request with an inherent limit on the data being transmitted (due to the practical limitations of URL length). The general limit for URL length is about 2,000 characters. Ideally, I would like to do a single POST request (to avoid the limit on the data being submitted).
幸运的是,当从特权代码(如在 Firefox 扩展中)使用 XMLHttpRequest 时,这些来源限制不适用,因此您可以直接使用它。如果它不起作用,请留下更多评论或打开一个新问题。
关于javascript - 从 Firefox 扩展与服务器通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6206120/