App inventor 2 en español
Cómo programar los teléfonos móviles con Android.
Curso de App inventor 2 en español - Juan Antonio Villalpando
-- Tutorial de iniciación de App Inventor 2 en español --
Volver al índice del tutorial
___________________________
169T2.- JavaScript. Ajax. PHP.
p169T_inyeccion.aia
- Este tutorial trata de ejecutar los ejemplos que encontramos en el capítulo 17 del libro:
learning php mysql javascript css & html5 - o'reilly
Learning PHP, MySQL & JavaScript_ with jQuery, CSS & HTML5 (4th ed.) [Nixon 2014-12-14].pdf
- Se trata de enviar una información mediante JavaScript a PHP utilizando AJAX.
- Estos códigos los subimos a un servidor web.
- Ejecutamos los html mediante el componente Web y el VisorWeb.
- Mediante POST
urlpost.html |
<!DOCTYPE html><html><head><title>AJAX Example</title></head>
<body style='text-align:center'>
<h1>Loading a web page into a DIV</h1>
<div id='info'>This sentence will be replaced</div>
<script>
params = "url=amazon.com/gp/aw"
request = new ajaxRequest()
request.open("POST", "urlpost.php", true)
request.setRequestHeader("Content-type","application/x-www-form-urlencoded")
request.setRequestHeader("Content-length", params.length)
request.setRequestHeader("Connection", "close")
request.onreadystatechange = function()
{
if (this.readyState == 4)
{if (this.status == 200)
{if (this.responseText != null)
{document.getElementById('info').innerHTML =this.responseText}
else alert("Ajax error: No data received")}
else alert( "Ajax error: " + this.statusText)}
}
request.send(params)
function ajaxRequest()
{try
{var request = new XMLHttpRequest()
}
catch(e1)
{try
{request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e2)
{try
{request = new ActiveXObject("Microsoft.XMLHTTP")}
catch(e3)
{request = false}
}
}
return request
}
</script>
</body></html>
|
urlpost.php |
<?php // urlpost.php
if (isset($_POST['url']))
{
echo file_get_contents('http://'.SanitizeString($_POST['url']));
}
function SanitizeString($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
return stripslashes($var);
}
?>
|
- Mediante GET
urlget.html |
<!DOCTYPE html><html><head><title>AJAX Example</title></head>
<body style='text-align:center'>
<h1>Loading a web page into a DIV</h1>
<div id='info'>This sentence will be replaced</div>
<script>
nocache = "&nocache=" + Math.random() * 1000000
request = new ajaxRequest()
request.open("GET", "urlget.php?url=amazon.com/gp/aw" + nocache, true)
request.onreadystatechange = function()
{if (this.readyState == 4)
{if (this.status == 200)
{if (this.responseText != null)
{
document.getElementById('info').innerHTML =
this.responseText
}
else alert("Ajax error: No data received")
}
else alert( "Ajax error: " + this.statusText)
}
}
request.send(null)
function ajaxRequest()
{try
{var request = new XMLHttpRequest()}
catch(e1)
{try
{request = new ActiveXObject("Msxml2.XMLHTTP")}
catch(e2)
{try
{request = new ActiveXObject("Microsoft.XMLHTTP")}
catch(e3)
{request = false}
}
}
return request
}
</script>
</body></html>
|
urlget.php |
<?php
if (isset($_GET['url']))
{
echo file_get_contents("http://".sanitizeString($_GET['url']));
}
function sanitizeString($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
return stripslashes($var);
}
?>
|
_________________
- Diseño.
_________________
- Bloques.
__________________________________
|