質問編集履歴
3
文法変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,12 +26,72 @@
|
|
26
26
|
|
27
27
|
```javascript
|
28
28
|
|
29
|
-
|
29
|
+
$(function(){
|
30
30
|
|
31
|
-
|
31
|
+
$("#button").click(function(event){
|
32
32
|
|
33
|
-
$
|
33
|
+
$.ajax({
|
34
34
|
|
35
|
+
type: "GET",
|
36
|
+
|
37
|
+
url: "text.php",
|
38
|
+
|
39
|
+
data: {val:null},
|
40
|
+
|
41
|
+
dataType : "text"
|
42
|
+
|
43
|
+
}).done(function(data){
|
44
|
+
|
45
|
+
var test = JSON.parse(data);
|
46
|
+
|
47
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
48
|
+
|
49
|
+
var data=test.split(/\n/).map(x=>{
|
50
|
+
|
51
|
+
return x.split(", ").map(x=>{
|
52
|
+
|
53
|
+
var y=x.split('=');
|
54
|
+
|
55
|
+
return {name:y[0],val:y[1]};
|
56
|
+
|
35
|
-
}
|
57
|
+
});
|
58
|
+
|
59
|
+
}).reduce((x,y)=>x.concat(y));
|
60
|
+
|
61
|
+
console.log(data);
|
62
|
+
|
63
|
+
});
|
64
|
+
|
65
|
+
}).fail(function(XMLHttpRequest, textStatus, errorThrown){
|
66
|
+
|
67
|
+
alert(errorThrown);
|
68
|
+
|
69
|
+
});
|
70
|
+
|
71
|
+
});
|
72
|
+
|
73
|
+
});
|
36
74
|
|
37
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
```php
|
80
|
+
|
81
|
+
$text=file("name.txt");
|
82
|
+
|
83
|
+
$text_array = array();
|
84
|
+
|
85
|
+
foreach($text as $row){
|
86
|
+
|
87
|
+
$params = explode(",",$row);
|
88
|
+
|
89
|
+
$text_array[$params[0]] = $params[1];
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
$json = json_encode($text_array);
|
94
|
+
|
95
|
+
echo $json;
|
96
|
+
|
97
|
+
```
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
for (var key in test){
|
32
32
|
|
33
|
-
$("#test").append('name:'+key + ' val:' +
|
33
|
+
$("#test").append('name:'+key + ' val:' + test[key]+ "<br/>");
|
34
34
|
|
35
35
|
}
|
36
36
|
|
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,9 +16,9 @@
|
|
16
16
|
|
17
17
|
名前=ハンバーグ, 分類=洋食, 主成分=タンパク質
|
18
18
|
|
19
|
-
名前=
|
19
|
+
名前=寿司, 分類=和食, 主成分=炭水化物
|
20
20
|
|
21
|
-
名前=
|
21
|
+
名前=牛乳, 分類=飲み物, 主成分=カルシウム
|
22
22
|
|
23
23
|
```
|
24
24
|
|