My "response.json" through "Request" is "null"

Hi,

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.

  1. First, what is the main difference between text and json?
  2. 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();

Try content type of application/x-www-form-urlencoded;charset=UTF-8

I tried changing

contentType: "application/json",

to:

contentType: "application/x-www-form-urlencoded;charset=UTF-8",

but it still resulted “console.log: my-addon: null”.

Web servers not always offer a JSON representation of the resource you are requesting. Which url are you trying to request?

Looks like https://www.mozilla.org/en-US/

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.

I was just using the mozilla website to test the retrieval of response in json. Thanks,

Cool so what was your final solution can you copy paste please.