前提・実現したいこと
ajaxのdataTypeについて調べていたのですが、
言葉としては理解したつもりですが、下記の場合どれを使えばよいかわからないため質問いたしました。
まだテスト段階なので動いてはいないですが、
htmlのformでチェックされたものの値をajaxからphpに送り
php内で配列の中でformからきた値と配列内の値が同じであれば取り出す(formからvalue="red"とvalue="b"がきた場合はidが2のものが他のcolor,typeの情報と共に取り出される)
取り出したものを(sortして)ajax.php内でhtmlを組みデータを代入しajax(js)に返す(htmlはヒットデータ分だけ繰り返し生成されるイメージ)
html自体はphp内で生成してjsでそれを取得して表示のみ
です。(伝わりにくいと思いますが。。。)
該当のソースコード
html
1<form id="form" name="search" action="" method="POST"> 2 3 <input type="radio" id="color01" name="color" value="red"><label for="color01">赤</label> 4 <input type="radio" id="color02" name="color" value="blue"><label for="color02">青</label> 5 6 <input type="radio" id="type01" name="type" value="a"><label for="type01">A</label> 7 <input type="radio" id="type02" name="type" value="b"><label for="type02">B</label> 8 <input type="radio" id="type03" name="type" value="c"><label for="type03">C</label> 9 10 <button class="submit" value="検索">検索</button> 11</form> 12<div class="result"></div>
js
1$.ajax({ 2 url: '/ajax.php', 3 type: "POST", 4 dataType: [???], 5 $('button').on('click',function(event){ 6 $('.result').html(html); 7...
php
1//ajax.php 2<?php 3mb_internal_encoding("UTF-8"); 4 5$data = [ 6 "test"=>[ 7 [ 8 "id"=>"1", 9 "color"=>"red", 10 "type"=>"a", 11 ], 12 [ 13 "id"=>"2", 14 "color"=>"red", 15 "type"=>"b", 16 ], 17 [ 18 "id"=>"3", 19 "color"=>"blue", 20 "type"=>"c" 21 ], 22 ] 23]; 24?>
また、dataTypeにdataTypeと書く記述もあったのですが、どういう状態なのでしょうか?
ご教示のほどよろしくお願いします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/31 00:44