Skip to content

Commit 462d73b

Browse files
committed
JavaScript / Ajax / Json
1 parent 67098cd commit 462d73b

File tree

3 files changed

+72
-9
lines changed

3 files changed

+72
-9
lines changed

Ejemplos/AjaxArray.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
11+
<a href="#" id="cargar">Cargar</a>
12+
<div id="listado"></div>
13+
14+
<script>
15+
document.getElementById('cargar').addEventListener('click',cargarArray);
16+
17+
function cargarArray(e){
18+
e.preventDefault();
19+
const xhr = new XMLHttpRequest();
20+
xhr.open('GET','AjaxJSON.txt',true);
21+
xhr.onload = function(){
22+
if(this.status === 200){
23+
console.log(JSON.parse(this.responseText));
24+
document.getElementById('listado').innerHTML = `${this.responseText}`;
25+
}
26+
}
27+
xhr.send();
28+
}
29+
</script>
30+
31+
</body>
32+
</html>

Ejemplos/AjaxJSON.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"array": [
3+
1,
4+
2,
5+
3
6+
],
7+
"boolean": true,
8+
"color": "#82b92c",
9+
"null": null,
10+
"number": 123,
11+
"object": {
12+
"a": "b",
13+
"c": "d",
14+
"e": "f"
15+
},
16+
"string": "Hello World"
17+
}

README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,29 @@ class Casa {
801801
>>Con la estructura anterior podemos obtener informacion pero hay que presentar la información que recibimos o enviamos de alguna manera y la mejor forma es utilizando estructura `JSON`.
802802
**[¿Qué es JSON (Click Aqui)?](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON)**.
803803

804+
## Ejemplo de un array y Ajax
805+
>### HTML
806+
```html
807+
<a href="#" id="cargar">Cargar</a>
808+
<div id="listado"></div>
809+
```
810+
>### JavaScript
811+
```js
812+
document.getElementById('cargar').addEventListener('click',cargarArray);
804813

805-
806-
807-
808-
814+
function cargarArray(e){
815+
e.preventDefault();
816+
const xhr = new XMLHttpRequest();
817+
xhr.open('GET','AjaxJSON.txt',true);
818+
xhr.onload = function(){
819+
if(this.status === 200){
820+
console.log(JSON.parse(this.responseText));
821+
document.getElementById('listado').innerHTML = `${this.responseText}`;
822+
}
823+
}
824+
xhr.send();
825+
}
826+
```
809827
---
810828
# JAVA SCRIPT FUNCIONES VARIAS
811829

@@ -842,7 +860,6 @@ class Casa {
842860

843861
### Ejemplo completo
844862
```html
845-
846863
<!DOCTYPE html>
847864
<html lang="en">
848865
<head>
@@ -869,11 +886,8 @@ class Casa {
869886
</script>
870887
</body>
871888
</html>
872-
873889
```
874890

875-
876-
877891
## Estructura / Explicación - JavaScript Select Multiple
878892

879893
>#### HTML
@@ -945,5 +959,5 @@ Alguna de las maneras de obtener el valor es utilziar un `event` el cual puede s
945959
}
946960
</script>
947961
</html>
962+
```
948963

949-
```

0 commit comments

Comments
 (0)