Ciao a tutti
Tramite un oggetto debbo restituire un valore di una chiamata ajax ecco il code:
con questo code mi da "undefined" come mai?codice:var obj = { xmlhttp: function(type, url, formdata) { const xhttp = window.XMLHttpRequest ? new XMLHttpRequest : ActiveObject("Microsoft_XMLHTTP"); xhttp.onreadystatechange = function() { if(xhttp.status === 200 && xhttp.readyState === 4){ return xhttp.responseText; } } xhttp-send(formdata); } }, search: function(){ const elSearch = document.querySelector("input[name=search]"); let response = obj.xmlhttp("POST", "http://......", elSearch.value); alert(response); } }
Ma se metto un alert al responseText i valori ci sono tutti.

Rispondi quotando