Skip to content

Instantly share code, notes, and snippets.

@toshimasa-nanaki
Created November 13, 2017 11:16
Show Gist options
  • Save toshimasa-nanaki/76dc5d7f984198060293927336d8d70d to your computer and use it in GitHub Desktop.
Save toshimasa-nanaki/76dc5d7f984198060293927336d8d70d to your computer and use it in GitHub Desktop.
APIを呼び出し(成功)
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$('#submit').on("click", function() {
$('#submit').prop("disabled", true);
$.ajax({
url: "./test.php",
type:'POST',
dataType: 'json',
data : {"method": $("#method").val(), "vulnId": $("#vulnId").val()},
timeout:10000,
}).done(function(data) {
if(data.Vulinfo != undefined){
$("#detail").html(data.Vulinfo.VulinfoData.Title);
$("ul").empty();
}else{
$("ul").empty();
$("#detail").empty();
data.item.forEach(function(element, index, array){
$("ul").append("<li>"+ element.title +"</li>");
})
}
$('#submit').prop("disabled", false);
}).fail(function(XMLHttpRequest, textStatus, errorThrown) {
alert("error");
$('#submit').prop("disabled", false);
})
});
});
</script>
<table border="0">
<tr>
<td align="right"><b> method:</b></td>
<td>
<select id="method">
<option value="getVulnOverviewList">getVulnOverviewList</option>
<option value="getVulnDetailInfo">getVulnDetailInfo</option>
</select>
</td>
</tr>
<tr>
<td align="right"><b> vulnId:</b></td>
<td><input type="text" name="vulnId" id="vulnId"></td>
</tr>
</table>
<input type="button" value="Submit" id="submit"/>
<div id="list">
<ul></ul>
</div>
<div id="detail"></div>
</body>
</html>
<?php
$baseUrl = "http://jvndb.jvn.jp/myjvn?";
$url = $baseUrl."method=".$_POST["method"]."&vulnId=".$_POST["vulnId"];
$result = file_get_contents($url);
$xml = simplexml_load_string($result,'SimpleXMLElement');
$json = json_encode($xml);
echo $json;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment