Tag: Javascript

Which programming language is the best one?

Is it really possible to answer this question?

Yes, the correct answer is: all of them. Or let’s ask another question first: for which problem?

There is not “the one and only” best programming language, there are tons. This question is simply not a good one. It’s good for endless discussion, but it’s neither complete, nor does it give you details about the problem to solve. An answer will not solve the unknown problem of the author. Every coding language has it advantages when it comes to solving a specific problem. But which one? There are advantages for JavaScript, Python, PHP, Java, Swift, Dart and others. But what if the author wants to write some firmware for a micro controller? Ok, you see the point.

But why do people ask those questions?

I see a lot of such questions posted on all social platforms. And as those questions are so incomplete, there are no correct answers. The results are endless discussions about the advantages of each coding language. And this is what most of the authors want: an open question which leads to endless attention. In detail: likes and retweets to pretend the algorithms to be an interesting account. Honestly, no one reads through thousands of responses. And if yes, you only see the advantages that each comfortable developer or user sees in his area of expertise. This might lead to some short attention, but it will never create some high quality and valuable content fo the users. And that’s a pity.

And what about: iOS or Android? Windows or macOS? Python or JavaScript? Same thing! The answers are just a time wasting mess.

Photo by Donald Giannatti on Unsplash.

AJAX: Asynchrones Senden eines HTTP-Requests

Zum Versenden eines asyncronen HTTP-Requests kann folgender Javascript-Code verwendet werden:

var req = new XMLHttpRequest();
req.onreadystatechange = handleStateChange;
req.open('GET', 'http://www.example.com/', true);
req.send(null);
 
function handleStateChange() {
  switch (req.readyState) {
    case 0: // UNINITIALIZED
    case 1: // LOADING
    case 2: // LOADED
    case 3: // INTERACTIVE
      break;
    case 4: // COMPLETED
      handleResponse (req.status, req.responseText);
      break;
    default: // fehlerhafter Status
    break;
  }
}
 
function handleResponse (status, responseText) {
  // verarbeiten der Daten ...
}

Werte für XMLHttpRequest.readyState:

  1. UNINITIALIZED – Noch nicht initialisiert, d.h. noch kein Aufruf von open().
  2. LOADING – Request wurde initialisiert, aber noch kein send().
  3. LOADED – Request wurde mittels send() abgesetzt.
  4. INTERACTIVE – Teile der Antwort sind bereits verfügbar. Auf die Daten kann über responseText zugegriffen werden.
  5. COMPLETED – Die Bearbeitung des Requests ist beendet.