Z
Z
zaratustraman12015-12-11 18:45:10
JavaScript
zaratustraman1, 2015-12-11 18:45:10

JSON, AJAX, XHR?

Good day!
I'm just starting to learn JS, so I have a question. I've been googling and reading articles for 4 hours now and can't reach me in any way.
So I wanted to deal with AJAX. And met with misunderstanding. On learn.javascript.ru they talk about XMLHttpRequest, but there is also $.ajax.

For example, I have the address of the page on which the format data is located:

{"nouns":["a","b","c"],"adjectives":["e","f","g","h"]}


I want to make an app that reads this data into two arrays: nouns and adjectives.
What should I use?
Tried with XTR:
var req = new XMLHttpRequest();
req.open('GET', 'https://my.site./dictionary', true);
req.send();
req.onload = function() {
  alert( this.responseText );
}


and via getJson:
$.getJSON( "https://my.site/dictionary", function( data ) {
  var nouns = data.nouns;
  var adjectives = data.adjectives;
});

But that's not it.

Please explain where I am wrong. Or should it be obvious, just that my brains are not for programming?

And another question about architecture.

If I want to make an application like this:
1 reads JSON data by reference
2 sorts them into different arrays
3 displays certain combinations of elements from each array
4 remembers the last n outputs, and if the generated output is repeated with the last n, then regenerate.

What do I need for this? What structure?
Create a JS object with methods:
1 read the data and sort it into arrays
2 generate a combination of elements, write to the last n combinations and output (if repeated, then regenerate).

I've been studying JS for 2-3 weeks, but I can't cope with this task for 5 hours already. Is this normal or a wake up call that this is not for me?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergeyj, 2015-12-11
@zaratustraman1

Read up to:

On learn.javascript.ru they talk about XMLHttpRequest, but there is also $.ajax.

Didn't read further.
You are learning javascript and the $.ajax / $.getJSON / $.post ... methods belong to the jquery library.
If you want to use jquery, then go to the site and see the documentation.
If you are interested in js, then read the information on the language and not on the library.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question