I’m using jpm to create an extension. I am having a difficulty trying to get a response in JSON as I keep getting “null”, where as receiving as text is fine.
First, what is the main difference between text and json?
How important is it to get json in order to manipulate the page easily?
3.1 Can you use XML DOM methods such as “getElementsByTagName” in Firefox SDK?
3.2 If not, can I use jQuery (i.e. $(“p”)) to manipulate the page?
I understand that these questions may make no sense as I am just a beginner coder. Because I got stuck here, I started CodeCademy tutorial on jQuery and half way through, to see if that helps. Here is the code that works (changing .text to .json does not work):
var Request = require("sdk/request").Request;
var someRequest = Request({
url: "https://www.mozilla.org/en-US/",
contentType: "application/json",
onComplete: function (response) {
var data1 = response.text;
console.log(data1);
}
});
someRequest.get();
Oh. I did not know we could only retrieve the response from request in .json only when the resource explicitly offered the JSON representation. Thanks.