Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用ajax从api获取json中的特定数据。这张照片对我来说很奇怪_Javascript_Json_Ajax_Api_Jsonp - Fatal编程技术网

Javascript 如何使用ajax从api获取json中的特定数据。这张照片对我来说很奇怪

Javascript 如何使用ajax从api获取json中的特定数据。这张照片对我来说很奇怪,javascript,json,ajax,api,jsonp,Javascript,Json,Ajax,Api,Jsonp,下面的代码是therasus同义词的代码。 查询搜索词为“退款” 我有以下代码 <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> </head> <body> <div id="data"></div> <script>

下面的代码是therasus同义词的代码。 查询搜索词为“退款” 我有以下代码

    <html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>


<div id="data"></div>

<script>
var urls = "http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/php";

$(document).ready(function() {
    $.get(urls,function(data) {
        $("#data").html(data);
    });
});
</script>       
</body>     
</html>
现在,我甚至不明白这一点。我只想在div中输入响应的某些部分…需要的单词是这部分的那些“Syn”:-

repayment
defrayal
defrayment
payment
return
repay
give back
pay

注意:根据用户查询,搜索词(即退款)可能会发生变化,这看起来很像PHP序列化格式:


检查此处的文档:

您的URL以
/php
结尾,根据本文档,它返回序列化的php数组。您想呼叫
http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/json
,注意结尾处的
/json

您还在这里共享API密钥,最好将其编辑掉。如果您想删除我的答案,我将编辑它。

谢谢大家

在@Walk给出正确答案后,我最终使用了

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>


<p>
<button>Click</button>
<div id="data"></div>

<script>
var urls = "http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/json";

$("button").click(function(){
    $.getJSON(urls, function(result){
        $("#data").html("");
        $.each(result, function(key1, value1){
            $.each(value1, function(key, value){
                $("#data").append(String(value).replace(/,/g,"<br>") + "<br>");
            });
        });   
    });
});
</script>       
</body>     
</html>


点击
变量URL=”http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/json";
$(“按钮”)。单击(函数(){
$.getJSON(URL、函数(结果){
$(“#数据”).html(“”);
$.each(结果、函数(键1、值1){
$。每个(值1,函数(键,值){
$(“#数据”)。追加(字符串(值)。替换(/,/g,“
”)+“
”); }); }); }); });
这不是JSON,这里是JSON:这不是JSON,但它看起来像某种结构。@Walk您是如何得到响应的。你能在这里帮我写下密码吗?请在下面写一个答案,只需在URL中用
/php
替换
/json
。该api是免费api,尚未付费。感谢您对/json注释的回复。我会尝试并标记我选择的答案,如果它有效的话。
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>


<p>
<button>Click</button>
<div id="data"></div>

<script>
var urls = "http://words.bighugelabs.com/api/2/648c23bcbb99d535a06e098b426a5b76/refund/json";

$("button").click(function(){
    $.getJSON(urls, function(result){
        $("#data").html("");
        $.each(result, function(key1, value1){
            $.each(value1, function(key, value){
                $("#data").append(String(value).replace(/,/g,"<br>") + "<br>");
            });
        });   
    });
});
</script>       
</body>     
</html>