Uncaught (in promise) SyntaxError: Bad control character in string literal in JSON at position 11858
上記のようなエラーが発生します。
ただし、サーバーに挙げた場合のみです。ローカル環境でテストした場合は上記のようなエラーは出ませんでした。
挙動としてはjavascriptでfetch文を書き、responseをphp側からjsonでもらいそれをcreateelementしてhtml内に追加するというような処理です。
全く原因がわからないのでお力添え願います。
php
1$key=filter_input(INPUT_POST,"key"); 2 $stmt=$this->pdo->prepare("SELECT id , title , comment , favorite FROM memo WHERE userId=:id AND title LIKE :key"); 3 $stmt->bindValue("id",$this->userId,\PDO::PARAM_INT); 4 $stmt->bindValue("key",'%'.$key.'%',\PDO::PARAM_STR); 5 $stmt->execute(); 6 return $stmt->fetchAll();
javascript
1const data=new FormData(); 2 data.append("key",input.value); 3 const res=await (await fetch("?action=edit",{method:"POST",body:data})).json(); 4 5 if(res.length){ 6 identical(res); 7 } 8function identical(list){ 9 const res_list=list; 10 const li_list=document.querySelectorAll("li"); 11 li_list.forEach(li =>{ 12 list.forEach(res =>{ 13 if(li.dataset.id === res.id){ 14 ul.insertBefore(li,ul.firstChild); 15 res_list.indexOf(res); 16 const index=res_list.indexOf(res); 17 res_list.splice(index,1); 18 } 19 }) 20 }) 21 create_li(res_list); 22} 23
回答1件
あなたの回答
tips
プレビュー