I’m trying to use Request.JSON in mooTools to bring in an object from a file I called “sample1.json” that is stored in the same folder locally. I did this successfully using jQuery’s “$.getJSON()”, which was trivially easy, but encountered difficulty doing this in mooTools.
Here’s my script:
var jsonRequest=new Request.JSON({
url: 'sample1.json',
onComplete: function(){
alert('JSON imported successfully!');
}
});
And here’s how ‘sample1.json’ looks:
{
"string": "The quick brown fox jumped over the lazy dog",
"number":1,
"object":{"width":1000,"height":2000},
"array":[0,60],
"null":""
}
I never get the alert message that I’m hoping for; I feel like it’s a trivial question, but after doing several hours of research trying to understand my error, I’m not getting anywhere. I appreciate any help you can offer.
Your problem is simply you’re never sending the request.
new Request.JSON()simple creates a new request object. You need to callsendto actually start the request. Also,onCompleteis called when the request is done successful or not, butonSuccessis what will have your json response: