从 api 获取结果 [英] Getting results from api

查看:27
本文介绍了从 api 获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用来自免费域 API 的 API 进行域可用性搜索.

I am trying to do a domain availability search using an API from free domain API.

在我创建帐户后,它显示:

After i create an account, it shows:

**Make a REST request using this URL:**
http://freedomainapi.com/?key=11223344&domain=freedomainapi.com

查看文档页面,它只有:

And looking in the documentation page, it has only:

请求 http://freedomainapi.com?key=YOUR_API_KEY&domain=DOMAIN_NAME

结果:

{
"status": "success",
"domain": "freedomainapi.com",
"available": false
}

我对 API 很陌生...

I am very new to APIs...

我需要的是显示一个域搜索框,当用户输入时,它应该返回结果.

What I need is to show a domain search box, and when the user enters, it should return with result.

它声称也显示域建议.我希望它也能奏效.

It claims to show domain suggestions as well. I hope it will also work.

推荐答案

使用 jquery 和 jsonp 代理

Using jquery and a jsonp proxy

http://jsfiddle.net/mp8pukbm/1/

$.ajax({
    type: 'GET',
    url: "https://jsonp.nodejitsu.com/?callback=?",
    data: {url: 'http://freedomainapi.com?key=14ejhzc5h9&domain=freedomainapi.com'},
    dataType: "jsonp",
    success: myfn 
});
function myfn(data) {
   console.log(data);
}

你必须使用代理,因为不允许跨域json

you have to use the proxy because cross domain json is not permitted

我进行了更新以在 div 中显示结果(字符串化)http://jsfiddle.net/mp8pukbm/2/

i made an update to show the result in a div (stringified) http://jsfiddle.net/mp8pukbm/2/

编辑 #2:我在该站点上创建了一个测试密钥,您必须使用自己的

EDIT #2: i created a test key on that site, you have to use your own

编辑 #3:还有你的组合:http://jsfiddle.net/mp8pukbm/4/

EDIT #3: and there's your combo: http://jsfiddle.net/mp8pukbm/4/

这篇关于从 api 获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆