質問するログイン新規登録

質問編集履歴

1

指摘をもらってなおしたところ

2017/09/09 14:50

投稿

eruko
eruko

スコア9

title CHANGED
File without changes
body CHANGED
@@ -88,9 +88,62 @@
88
88
  });
89
89
  ```
90
90
 
91
+ ###なおしたことその2
92
+ php側で
93
+ json_decode()→json_encode()のみにして
94
+ header('Content-Type~はdatatypeがjsonなら不要なのではずした。
95
+ また、
96
+ 指摘を頂いてphp側に
97
+ echo json_encode(array(
98
+ 'ban' => 'ban1',
99
+ 'nam' => 'nam1',
100
+ 'ttl' => 'ttl1',
101
+ 'gaz' => 'gaz1',
102
+ 'dat' => 'dat1',
103
+ ));
91
104
 
105
+ json側でちゃんと読込まれていたので
106
+ 原因はphp側と判明。
92
107
 
108
+ ```gallery2.php
109
+ <?php
110
+ require_once('./php/ponta.php');
111
+ $db->query('set names utf8');
112
+ $ps = $db->query('select * from wan2 order by ban desc');
113
+ $users = [];
93
114
 
115
+ while ($row = $ps->fetchObject())
116
+ {
117
+ $users[] = array(
118
+ 'ban'=> $row->ban
119
+ ,'nam' => $row->nam
120
+ ,'ttl' => $row->ttl
121
+ ,'mes' => $row->mes
122
+ ,'gaz' => $row->gaz
123
+ ,'dat' => $row->dat
124
+ );
125
+ }
126
+
127
+ echo json_encode($users);
128
+ ?>
129
+ ```
130
+ 一応js側
131
+ ```js
132
+ $.ajax({
133
+ type: "POST",
134
+ data: "gallery2.php",
135
+ dataType: "json",
136
+ crossDomain: false,
137
+ scriptCharset: "UTF-8",
138
+ cache: false
139
+ }).done(function(data) {
140
+ //console.log(data);
141
+ console.log($.parseJSON(data));
142
+ }).fail(function(XMLHttpRequest, textStatus, errorThrown) {
143
+ alert('Error : ' + errorThrown);
144
+ });
145
+ ```
146
+
94
147
  ###補足情報(言語/FW/ツール等のバージョンなど)
95
148
  PHP 5.6.31
96
149
  jquery-2.1.1