#前提・実現したいこと
行政機関が公表しているAPI(XMLデータ)を利用して、特定のデータを取得・表示するwebアプリを作成しています。APIの公開は2017年6月であり、比較的新しいものです(2018年3月に仕様更新)。
取得・表示する機能はJavascript(ajax)で記述しており、アプリ画面上のボタンをクリックすると当該機能が発動するようになっています。
本件については、HPKPの問題があり、下記スレッドで質問させていただきました。
アドバイスを踏まえてphpで中継プログラムを作成したところ、HPKPに関するエラーメッセージは消え、この点は一応解決しました。
HPKP(HTTP公開鍵ピンニング)を採用したサイトにAPI接続する方法
https://teratail.com/questions/162053
#発生している問題・エラーメッセージ
アプリ画面上のボタンを押して機能を発動させると、Developer Toolsの「Network」には以下が表示され、正常にxmlデータが取得できているように見えます。「Network」の「Response」タブにも、取得したかったxmlデータが表示されています。
<General> Request URL: ●●●
Request Method: GET
**Status Code: 200 **
Remote Address: ●●●
Referrer Policy: no-referrer-when-downgrade
<Response Headers> content-type: application/xml date: Wed, 05 Dec 2018 15:41:21 GMT server: nginx **status: 200** x-powered-by: PHP/7.2.10
<Request Headers> :authority: ●●● :method: GET :path: ●●● :scheme: https accept: application/xml, text/xml, */*; q=0.01 accept-encoding: gzip, deflate, br accept-language: ja,en-US;q=0.9,en;q=0.8 referer: ●●● user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36 x-requested-with: XMLHttpRequest _: 1544024458025
しかし、他方で、「Console」には以下が表示され、何度やってもエラー側の処理が実行されてしまいます。
XMLHttpRequest : 0
textStatus : timeout
errorThrown : undefined
#試したこと
現時点のJavascript及びphpのコードは以下のとおりです。
何かよい解決策はないものでしょうか。。
Javascript
1$('#btn').on('click', function(){ 2 $.ajax({ 3 url:'●●●.php', 4 type:'GET', 5 dataType:'xml', 6 cache:false, 7 timeout:1000, 8 error:function(XMLHttpRequest, textStatus, errorThrown) { 9 console.log("ロード失敗"); 10 console.log("XMLHttpRequest : " + XMLHttpRequest.status); 11 console.log("textStatus : " + textStatus); 12 console.log("errorThrown : " + errorThrown.message); 13 }, 14 success:function(xml){ 15 $(xml).find("#●●●").each(function() { 16 $("#result").append("#●●●"); 17 }); 18 } 19 }); 20}); 21
php
1<?php 2 header("Content-type: application/xml"); 3 $url = "●●●"; 4 readfile($url); 5?>
回答2件
あなたの回答
tips
プレビュー