简体   繁体   English

将jQuery添加到firefox扩展

[英]adding jquery to firefox extension

I have created a simple firefox addon consisting mainly from the main.js file but I need to use jquery for ajax. 我创建了一个简单的firefox插件,主要由main.js文件组成,但我需要对ajax使用jquery。 but I have no clue on how can I add script to my project so it could be accessible. 但是我不知道如何将脚本添加到项目中以便可以访问脚本。 Please help! 请帮忙!

I found this example but still says that $ is undefined 我找到了这个例子,但仍然说$是未定义的

var data = require("sdk/self").data;

contentScriptFile: data.url("jquery-1.11.2.min.js")

Include the jquery file before other scripts file ie the custom javascript file. 在其他脚本文件(即自定义javascript文件)之前添加jquery文件。 You might be including the file after your custom javascript file which uses jQuery. 您可能在使用jQuery的自定义javascript文件之后添加了该文件。 That's the reason $ is undefined 这就是$ undefined的原因

but I need to use jquery for ajax 但是我需要对ajax使用jquery

No, ajax requests can actually be issued without jquery. 不,实际上可以在没有jquery的情况下发出ajax请求。 After all jquery just provides convenience wrappers around standard browser APIs. 毕竟,jquery只是提供了围绕标准浏览器API的便利包装。

The XMLHttpRequest constuctor is available in content scripts and as net/xhr module in the addon main. XMLHttpRequest构造函数可在内容脚本中使用,也可以在附加组件主程序中作为net / xhr模块使用。

For transforming the result into HTML, mozilla does support xhr.responseType = "document" which turns the response into a html document whose nodes can be inserted into the target document. 为了将结果转换为HTML,mozilla确实支持xhr.responseType = "document" ,它将响应转换为html文档,其节点可以插入到目标文档中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM