Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.javascript > #4948

Re: not a function

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups de.comp.lang.javascript
Subject Re: not a function
Date 2018-04-29 01:14 +0200
Organization PointedEars Software (PES)
Message-ID <50c4e95f-82dd-87c4-69f8-3531597d9572@PointedEars.de> (permalink)
References <pbppha$jg2$1@news.albasani.net> <5377515.lOV4Wx5bFT@PointedEars.de> <pbrpju$8v9$1@news.albasani.net>

Show all headers | View raw


Jan Novak wrote:

> Am 25.04.18 um 21:04 schrieb Thomas 'PointedEars' Lahn:
>> Jan Novak wrote:
>>> Ich habe folgenden JS Code aus bootstrap-treeview übernommen:
>>
>> Nein, hast Du _nicht_, sondern Du hast *wieder* ohne Sinn und Verstand
>> Copy & Pray gemacht :-(
>
> Du solltest Lehrer werden ;-)

Das hab’ ich schon oft gehört.  Vielleicht später mal, im Moment hab’ ich
genug mit meinen eigenen Studien zu tun.

> Ich hatte bisher leider keine Zeit, neben Arbeit, Beruf, Familie, Kinder
> und und und auch noch einen mehrmonatigen JS Kurs zu machen ;-)

Das ist auch nicht nötig.  Jeden Abend ein bisschen lernen genügt schon.
/Festina lente/, wie der Lateiner sagt.

Weil Du es anscheinend noch nicht gefunden hast:

<https://developer.mozilla.org/de/docs/Web/JavaScript>

>>    function (data) { … }
>>
>> als zweites Argument von $.getJSON() ist offensichtlich ein *Callback*,
>> der ausgeführt wird, wenn der Server auf den HTTP-Request (URI angegeben
>> durch das erste Argument) *geantwortet* hat.
>> Die Antwort vom Server trifft in der Regel ein, *nachdem* $.getJSON()
>> ausgeführt wurde *und* *zurückgekehrt* ist.  Der Rückgabewert des
>> Callbacks landet also _nicht_ in “initSelectableTree”, sondern wird (in
>> der Regel) *weggeworfen*.
>
> Wie kann dann überhaupt irgendetwas funktionieren?

Du musst *im Callback* das tun, was passieren soll, wenn die Antwort kommt.

>> Du willst folgendes machen:
>>
>>    .---------------- Client --------------.
>>    :                                      :
>>
>>     Script                   HTTP API
>>     Server
>>       :                         :                                     :
>>      .-.       $.getJSON()      :                                     :
>>      : :---------------------->.-.  GET /include/fetch.php HTTP/1.x   :
>>      : :                       : :---------------------------------->.-.
>>      : :  undefined/:: Promise : :                                   : :
>>      : :<- - - - - - - - - - --'-'                                   : :
>>      : :                                                             : :
>>      : :      DOM API    function (data)       HTTP/1.x 200 OK       : :
>>      : :         :             .-.<- - - - - - - - - - - - - - - - --'-'
>>      : :        .-.<-----------: :                                    :
>>      : :        : :            : :                                    :
>>      : :        '-'- - - - - ->: :                                    :
>>      : :         :             '-'                                    :
>>      '-'         :              :                                     :
>>       :          :              X                                     :
>>       X          :                                                    :
>
> Ich lande also hier ..............^ statt wie gewünscht
> hier ...^

Du landest an *beiden* Stellen, aber Du machst (vermutlich sogar) das
(Richtige) an der fhcsalen Stelle.

>> Demgegenüber machen die Bootstrap-Leute im Originalcode etwas *völlig*
>> *anderes*:
>> […]
>> (Schau Dir mal an, wo “defaultData” herkommt.)
>
> defaultData kam aus einerm statischen Array innerhalb JS,

Aus einem Array, richtig.  (Arrays sind _nicht_ statisch in ECMAScript-
Implementierungen.)

> was natürlich in einem Programm witzlos ist, denn die Daten, welche
> angezeigt werden sollem, kommen natürlich aus einer Datenbank.

Genau.  Du hast ja inzwischen herausgefunden, dass Du deshalb im Callback
ansetzen musst.

>> Jetzt klar?
>
> Naja... ein wenig...
> Mir fehlen die Basics in JS, unter anderem die a-/synchrone Verarbeitung
> und die Verkettung von Variablen und Funktionen.
>
> Nichts desto trotz möchte ich JS in meinem PHP Programm nutzen können.

Das geht (AFAIK) nicht.  Du meinst was anderes, und ohne Obiges zu lernen
wird das nicht möglich sein.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to de.comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

not a function Jan Novak <repcom@gmail.com> - 2018-04-25 13:41 +0200
  Re: not a function Sascha Hüdepohl <news@juenger-der-himmlischen-teekanne.de> - 2018-04-25 17:49 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 07:39 +0200
  Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-25 21:04 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 07:55 +0200
      Re: not a function "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2018-04-28 19:50 +0200
      Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-29 01:14 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 08:07 +0200
      Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-29 01:30 +0200
        Re: not a function Jan Novak <repcom@gmail.com> - 2018-05-02 15:06 +0200
          Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-05-05 01:00 +0100

csiph-web