XMLHttpRequest response "dirty HTML" [closed]

1

I've done 3 functions to optimize the XMLHttpRequest:

function _ (x){
	return document.getElementById(x);
}
function ajaxObj (meth, url){
	var x = new XMLHttpRequest();
	x.open(meth, url, true);
	x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	return x;
}
function ajaxReturn (x){
	if(x.readyState==4 && x.status==200){
		return true;
	}
}

I call the 3 functions this way:

function ativar(){
      var codigo=_("codigo").value;
      var ajax = ajaxObj("POST", "verif_cad.php");
      ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
          alert(ajax.responseText);
          }
        }
      ajax.send("codigo="+codigo+"&us="+u);
 }

When I use html () or innerHTML of the ajax response through ajax.responseText I have no problem. But when I want to compare the answer with an if, or use the answer as a numeric variable, it does not work because it "looks dirty" as in that image obtained by alert (ajax.responseText):

HowdoIgetthe"clean" answer, in this case 48?

    
asked by anonymous 11.08.2017 / 04:07

0 answers