检索和显示jQuery GET请求的结果
Retrieve and display results of jQuery GET request
我试图从ESV API检索和显示数据:http://www.esvapi.org/
它正在codecademy.com域名上工作,而不是esvapi.org域名。
参见:http://jsfiddle.net/BinaryAcid/yqCcn/
<input type="button" value="get data" id="btn" >
$("#btn").click(function() {
var response = '';
$.ajax({ type: "GET",
// url: "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=John+1",
url: "http://www.codecademy.com/",
async: false,
success : function(text)
{
response = text;
}
});
document.write(response);
});
我尝试了fiddle的例子,但没有与第一个或第二个URL的工作,问题是有关的跨域调用,你不能直接调用一个服务,不是在你自己的域,除非你使用json或设置一些头在你的服务器明确允许跨域调用(这种技术不会在IE中工作)
可以。参见jsfiddle: http://jsfiddle.net/BinaryAcid/qDrw8/1/
<input type="button" value="get data" id="btn" >
$("#btn").click(function() {
reference='Jhon+1'
$.getJSON('http://www.esvapi.org/crossref/ref.php?reference=' + reference + '&callback=?',
function(text){
if(text){
$('body').html(text.content);
} else {
$('body').html('Error');
}
});
});
雅虎查询语言(YQL)解决方案。参见jsfiddle: http://jsfiddle.net/BinaryAcid/jbCuH/1/
<input type="button" value="get data" id="btn">
$("#btn").click(function () {
var response = '';
var url = "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=John+1";
var yql = "select content from data.headers where url='" + url + "'";
$.ajax({
type: "GET",
url: "http://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(yql) + "&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?",
async: false,
dataType: "json",
success: function (data) {
response = data.query.results.resources.content;
document.write(response);
}
});
});
相关文章:
- JSONP请求返回结果,但也触发error_callback
- 轮询:获取请求直到结果合适
- 根据GET请求的结果自定义页面内容
- 从 Angular 数据工厂中的 HTTP POST 请求接收未定义的结果
- 正确显示从 ajax 请求到 html 的结果
- MongoDB MonkAPI根据数据库请求之外可用的查找结果设置变量
- 将ajax请求结果分配给jquery函数中的变量
- AJAX请求结果为空-清除我们的HTML输入字段
- 返回 WinJS.xhr 请求结果
- 带有IE9的jQuery$.ajaxPOST请求结果为空数组
- 在我的示例中,如何获得多个http请求结果
- 在我的案例中,如何传递http请求结果
- jQuery:如何将两个请求结果连接到json服务器
- javascript通过自身函数返回ajax请求结果
- 从AJAX请求结果更新引导警报文本
- 在Batman.js中返回请求结果的问题
- Express.js缓存请求结果与动态数据
- 使用javascript请求结果作为<进度>
- 当离开状态时,如何停止http请求或停止处理http请求结果
- Indexeddb:如何获取请求结果和游标值