我想使用 readability parser API但是当我调用这个 API 时,我得到空白/没有响应。
当我尝试使用其他一些 url 时,相同的代码给出了正确的响应。
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8;">
<head>
<script language="javascript">
var getJSON = function(url, successHandler, errorHandler) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
alert("-------" + url);
//xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
alert("===========" + status);
if (status == 200) {
successHandler && successHandler(xhr.response);
} else {
errorHandler && errorHandler(status);
}
};
xhr.send();
};
function getReading() {
var url1 = "https://www.readability.com/api/content/v1/parser?url=";
var testurl = "http://www.saptechnical.com/Tutorials/WebDynproABAP/ALV/page1.htm";
var urltoken = "&token=tokenkeyhere";
var finalurl = url1 + testurl + urltoken;
alert(finalurl);
getJSON(finalurl, function(data) {
alert(data.domain);
});
}
</script>
</head>
<body>
<input type="button" value="go" onClick="getReading()" />
</html>
最佳答案
我得到了答案,代码现在可以工作了.. 我使用 getJSON 方法调用 API。
function getInfo() {
var url = $("#txtSubmitlink").val();
$.getJSON("https://www.readability.com/api/content/v1/parser?url="+ url +"&token=tokenkeyhere&callback=?",
function (data) {
$("#dvContent").html(data.content);
$("#imgLeadImage").attr('src', data.lead_image_url);
});
}
谢谢大家-
关于javascript - 可读性API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20915421/