This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
fetch return außerhalb von Funktion nutzen
#1
Hallo,
wie kann ich den output_json außerhalb meiner Funktion nutzen bzw. was muss ich an dieser Funktion ändern damit es klappt?
Vielen Dank für eure Hilfe

lists = getContentFromPHP(1,'loadListNames_your.php')
console.log(lists)

function getContentFromPHP(param1,php_function){
    const params = new FormData();
        params.append('post_var', param1);
        fetch(php_function, {
            method: 'post',
            body: params
        }).then(res => {
            return res.text();
        }).then(res => {
            output = res;
            let output_json = JSON.parse(output);
            console.log(output_json)
           
        })
        return output_json
}
Zitieren
#2
steht in console.log(output_json) das drinn was du brauchst ?
Dann sollte das return doch da hin , oder liege ich da falsch ?

Ich muss das gleich mal testen weil fetch ist noch nicht so mein ding
Als Lösung markieren Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste