Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Websocket - String über nodeJS Server ersetzen

Empfohlene Antworten

Hallo zusammen,

Ich arbeite momentan an einem Projekt und benötige dringend Hilfe!

Ich habe ein kleines Javascript Progrämmchen, welches Strings scannt und falls diese mit einer Zeichenkette übereinstimmen an einen nodeJS Server schickt und die Antwort dann durch den alten Text ersetzt.

So sähe es in der Theorie aus:

"Hello %username%" => Found %username% => Send "username" to the server => Server answer: "Benutzerkonto1" => Replace server answer with the current %username%

Mein bisheriger Code:

Function.scanForServerText(data, function(key) {

    console.log(key);

});


scanForServerText: function(data, callback) {

        Object.keys(data).forEach( function(key) {

            if ( data[key] instanceof Object ) {

                Function.scanForServerText(data[key]);

            } else {

                var replace = data[key].toString().match("%(.*)%");

                    if ( replace ) {

                        Connection.send(["getUserData", replace[1]], function(key) {

                            if ( key && key.length ) {

                                callback(key);

                            }

                        }); 

                    }

            }

        });

    },

Ich hänge schon seit über einer Woche an dem Problem, zum einen wird das Callback in der scanForServerText Funktion undefined, zum anderen bin ich mir nicht sicher ob das wirklich die beste Lösung ist.

Wie ich es auch drehe oder neu schreibe, es will nicht funktionieren.

Wäre heilfroh über einen Hilfeansatz oder am besten einer Lösung:-)

Grüße

Ich kann dir bei deinem eigentlichen Problem nicht viel helfen aber ich denke das dein RegExp da eventuell quer schiesst sobald du sachen wie "Hello %username% from %country%"... Dein RegExp würde hier durch das (.*) alles zwischen zwei %-Zeichen scannen. also auch "username% from %country". Du musst einen RegExp benutzen der Greedy nach dem nächstens % sucht und nur bis dahin ;)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.