index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JavaScript And JSON</title>
</head>
<body>
<h2>Links</h2>
<ol id="links">
</ol>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="myscript.js"></script>
</body>
</html>
myscript.js
$(document).ready(function() {
$.getJSON('data.json', function(info){
var output='';
for (var i = 0; i <= info.links.length-1; i++) {
for (key in info.links[i]) {
if (info.links[i].hasOwnProperty(key)) {
output += '<li>' +
'<a href = "' + info.links[i][key] +
'">' + key + '</a>';
'</li>';
}
}
}
var update = document.getElementById('links');
update.innerHTML = output;
}); //getJSON
}); // ready
data.json
{
"full_name" : "Ray Villalobos",
"title" : "Staff Author",
"links" : [
{ "blog" : "http://iviewsource.com" },
{ "facebook" : "http://facebook.com/iviewsource" },
{ "podcast" : "http://feeds.feedburner.com/authoredcontent" },
{ "twitter" : "http://twitter.com/planetoftheweb" },
{ "youtube" : "http://www.youtube.com/planetoftheweb" }
]
}
viernes, 27 de septiembre de 2013
usar json con ajax
var request;
if (window.XMLHttpRequest) {
request=new XMLHttpRequest();
} else {
request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.open('GET', 'data.json');
request.onreadystatechange = function() {
if ((request.status === 200) &&
(request.readyState === 4)) {
info = JSON.parse(request.responseText);
var output='';
for (var i = 0; i <= info.links.length-1; i++) {
for (key in info.links[i]) {
if (info.links[i].hasOwnProperty(key)) {
output += '<li>' +
'<a href = "' + info.links[i][key] +
'">' + key + '</a>';
'</li>';
}
}
}
var update = document.getElementById('links');
update.innerHTML = output;
} //ready
} //event
request.send();
if (window.XMLHttpRequest) {
request=new XMLHttpRequest();
} else {
request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.open('GET', 'data.json');
request.onreadystatechange = function() {
if ((request.status === 200) &&
(request.readyState === 4)) {
info = JSON.parse(request.responseText);
var output='';
for (var i = 0; i <= info.links.length-1; i++) {
for (key in info.links[i]) {
if (info.links[i].hasOwnProperty(key)) {
output += '<li>' +
'<a href = "' + info.links[i][key] +
'">' + key + '</a>';
'</li>';
}
}
}
var update = document.getElementById('links');
update.innerHTML = output;
} //ready
} //event
request.send();
Recorrer un objeto json
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JavaScript And JSON</title>
</head>
<body>
<h2>Links</h2>
<ul id="links">
</ul>
<script>
var info = {
"full_name" : "Ray Villalobos",
"title" : "Staff Author",
"links" : {
"blog" : "http://iviewsource.com",
"facebook" : "http://facebook.com/iviewsource",
"youtube" : "http://www.youtube.com/planetoftheweb",
"podcast" : "http://feeds.feedburner.com/authoredcontent",
"twitter" : "http://twitter.com/planetoftheweb"
}
};
var output = "";
for ( key in info.links ) {
if (info.links.hasOwnProperty(key)) {
output += '<li>' +
'<a href = "' + info.links[key] +
'">' + key + '</a>' +
'</li>';
} //if the links has the key property
} // for...go through each link
var update = document.getElementById('links');
update.innerHTML = output;
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JavaScript And JSON</title>
</head>
<body>
<h2>Links</h2>
<ul id="links">
</ul>
<script>
var info = {
"full_name" : "Ray Villalobos",
"title" : "Staff Author",
"links" : {
"blog" : "http://iviewsource.com",
"facebook" : "http://facebook.com/iviewsource",
"youtube" : "http://www.youtube.com/planetoftheweb",
"podcast" : "http://feeds.feedburner.com/authoredcontent",
"twitter" : "http://twitter.com/planetoftheweb"
}
};
var output = "";
for ( key in info.links ) {
if (info.links.hasOwnProperty(key)) {
output += '<li>' +
'<a href = "' + info.links[key] +
'">' + key + '</a>' +
'</li>';
} //if the links has the key property
} // for...go through each link
var update = document.getElementById('links');
update.innerHTML = output;
</script>
</body>
</html>
sábado, 21 de septiembre de 2013
Creando un entornovirtual
Creando un entorno virtual
Para crear un entorno virtual solo basta con situarse en la carpeta donde se ubicará y luego ejecutar:
$ virtualenv __nombre__
Siendo __nombre__ el nombre del entorno que deseas crear. Después, para acceder a él, deberás colocar:
$ cd __nombre__$ source bin/activate
Si estas en Windows:
$ cd __nombre__$ Scripts\activate.bat
Listo.
Por ultimo, dentro del entorno virtual, para instalar Django en cualquier sistema operativo solo basta con ejecutar:
$ pip django -U
-U lo colocamos para obtener la última versión.
Ahora todo se instalará y ejecutará dentro del entorno virtual. Si deseas colocar algo de manera global, la instalación deberá ser fuera de este.
miércoles, 4 de septiembre de 2013
Instalar python
En Linux:
En linux ya tienes instalado Python, así que solo queda instalar easy_install, pip y virtualenv.Ten en cuenta ser superusuario para cada uno de los comandos a ejecutar.
Para easy_install (si no lo tienes instalado):
$ sudo apt-get install python-setuptools python-dev build-essential
Ahora instalamos pip y virtualenv:
$ easy_install pip$ pip install virtualenv
Suscribirse a:
Entradas (Atom)