简体   繁体   中英

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. 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. You might be including the file after your custom javascript file which uses jQuery. That's the reason $ is undefined

but I need to use jquery for ajax

No, ajax requests can actually be issued without jquery. After all jquery just provides convenience wrappers around standard browser APIs.

The XMLHttpRequest constuctor is available in content scripts and as net/xhr module in the addon main.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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