Created
February 24, 2015 05:11
-
-
Save jamc92/1591cc1fc5f626f02c34 to your computer and use it in GitHub Desktop.
JS - Some AJAX (don't remember if it does work)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Ajax Suggestion</title> | |
<script> | |
//Declaro la funcion con un parametro que tomara el string que se coloque en el input | |
function showHint (srt) { | |
//Si no hay nada escrito que devuelta vacio | |
if (srt.length == 0) { | |
document.getElementById("txtHint").innerHTML=""; | |
// Sino, que declare un objeto de peticion xmlhttp | |
} else { | |
var xmlhttp = new XMLHttpRequest(); | |
//Que al cambiar el estado y sean igual a 4 y 200 envie la respuesta del contenido del texto | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
document.getElementById(txtHint).innerHTML=responseText; | |
} | |
} | |
//Se abra el archivo con la peticion, nombre, peticion de la variable asignandole el str correspondiente y el booleano true | |
xmlhttp.open("GET", "gethint.php?q=" + str, true); | |
//Se envia la respuesta final | |
xmlhttp.send(); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<!--Así llamaría el valor al momento de estar typeando dentro de un input--> | |
<form> First Name: <input type="text" onkeyup="showHint(this.value)"> </form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Show Customer</title> | |
<script> | |
function showCustomer (str) { | |
var xmlhttp; | |
if (str == "") { | |
document.getElementById("myDiv").innerHTML=""; | |
return; | |
} | |
if (window.XMLHttpRequest) { | |
xmlhttp = new XMLHttpRequest(); | |
} else { | |
xmlhttp = ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
document.getElementById("myDiv").innerHTML=responseText; | |
} | |
} | |
xmlhttp.open("GET", "getcustomer.asp?q="+str,true); | |
xmlhttp.send(); | |
} | |
</script> | |
</head> | |
<body> | |
<!--Así llamaria a la funcion dentro de un select--> | |
<form onchage="showCustomer(this.value)"></form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment