return a ajax output

0

I have a question.

How to change the ajax function so that it returns the value of output variable.

function ajax(url, data)
        {
            const http = new XMLHttpRequest();
            http.open('post', url, true);
            http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            http.onload = function()
            {
                if(http.status === 200 || http.status == 0)
                {
                    var output = http.responseText;
                }
            }
            http.send(data);
            // return the value of output
        }
0

Hi.

function ajax(url, data)
        {
          let output =null;
            const http = new XMLHttpRequest();
            http.open('post', url, true);
            http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            http.onload = function()
            {
                if(http.status === 200 || http.status == 0)
                {
                    output = http.responseText;
                }
            }
            http.send(data);
            // return the value of output
           return output; 
        }

1 użytkowników online, w tym zalogowanych: 0, gości: 1