Xmlhttprequest "dirty HTML" answer

Asked

Viewed 36 times

1

I did 3 functions to optimize 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 that 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 by ajax.responseText I have no problem. But when I want to compare the answer to an if, or use the answer as a numeric variable, it doesn’t work because it "looks dirty from HTML" as in this image obtained by Alert(ajax.responseText):

inserir a descrição da imagem aqui

How do I get the "clean" answer, in this case, 48 ?

  • Check how your file is verif_cad.php if containing codes HTML it will surely return this code, otherwise it will not

  • Must be something in your PHP.

  • In verif_cad.php there is only PHP, in the Ajax file that has HTML

  • To test, I put all the javascript in a separate file without HTML tags and still have the same problem.

  • The related.php file was tagged with HTML tags! In a video tutorial the guy said to always put the HTML tags, even in PHP files to be included in others. Until now, Unda had been trouble!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.