javascript - 尝试使用 Indeed API 根据输入字段检索职位时出错

标签 javascript html api

我一直在尝试使用 Indeed.com 的 API 根据位置搜索职位。但是,我不断收到错误消息

https://ip-api.com/json/?callback=jQuery2140044062367054279905_1470512340351&_=1470512340352无法加载资源:net::ERR_CONNECTION_REFUSED

这是我的代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Indeed Job search result</title>
    <script src="//code.jquery.com/jquery-2.1.4.js" type="text/javascript"></script>

    <style type="text/css">
       .pagination li{
            background-color: #000;
            padding: 5px;
            float:left;
            margin-right: 2px;
            border-radius: 5px;
            color: #FFF;
            cursor: pointer;
        }
    </style>
</head>
<body>
<script>

jQuery(function() {

    var resultLinks = $('body').find('#pagination');

    var location, country, city, region, limit = 10;
    $.get("//ip-api.com/json/", function (response) {
        console.log(response);
        city = (isNull(response.city))?(response.city+","):"";
        region = (isNull(response.region))?(response.region):"";
        location = city + region;
        country = response.country;
        console.log(country);
    }, "jsonp");

    $( "#searchResult" ).click(function() {
        jobSearch($('#location').val(),$('#jobname').val(),country,0,limit);
    });

    resultLinks.on('click', 'li', function (e) {
        var start = ($(this).text() - 1) * limit, end = start + limit;
        jobSearch($('#location').val(),$('#jobname').val(),country,start,end);
    });

    function isNull(value){
        if(typeof(value) === "object" || typeof(value) === "undefined" || value === "null" || value === "")
            return false;
        else
            return true;
    };
    function extractDomain(url) {
        var domain;
        //find & remove protocol (http, ftp, etc.) and get domain
        if (url.indexOf("://") > -1) {
            domain = url.split('/')[2];
        }
        else {
            domain = url.split('/')[0];
        }

        //find & remove port number
        domain = domain.split(':')[0];

        return domain;
    };
    function jobSearch(location,data,country,start,end){
        var serachData  =data;
        $.ajax({
            cache: false,
            data: $.extend({
                publisher: '7778623931867371',
                v: '2',
                format: 'json',
                q: data,
                l: location,
                radius: 50,
                limit:limit,
                sort: 'date',
                highlight: 1,
                filter: 1,
                latlong: 1,
                co: country.toLowerCase(),
                userip: '',
                useragent: ''
            }, { start: start, end: end }),
            dataType: 'jsonp',
            type: 'GET',
            timeout: 5000,
            url: '//api.indeed.com/ads/apisearch'
        })
        .done(function( data ) {
            var result="",pagination = "",i=2,style,url, paginationLimit = Math.ceil((data.totalResults)/limit);

            $.each( data.results, function( i, item ) {
                style = ((i%2) == 0)?"articaljoblistinggray":"articaljoblistingwhite"
                result = result + '<a target="_blank" href="'+item.url+'"><li class="articaljoblisting '+style+'" style="margin-bottom:3px;">'+item.jobtitle+'<br /><span style="color:black;">'+item.source+' - '+item.formattedLocation+'</span></li></a>';
                i++;
                url = item.url;
            });

            for (i = 1; i <= paginationLimit; i++) {
                pagination = pagination + '<li>'+i+'</li>';
            }

            $('#jobs-data').html('<ul style="list-style: none;margin: 0;padding:0;">'+result+'</ul><a style="float: right;" target="_blank" href="http://'+extractDomain(url)+'/jobs?q='+serachData+'&l='+location+'">Find more jobs</a>');
            $('#pagination').html('<ul class="pagination" style="list-style: none;margin: 0;padding:0;">'+pagination+'</ul>');
        });
    };
});

</script>
</body>
</html>

感谢任何帮助!

最佳答案

无法从浏览器访问此 URL。 https://api.indeed.com/ads/apisearch但这可以是https://www.indeed.com/ 。请检查您是否有正确的 API 调用 URL。

关于javascript - 尝试使用 Indeed API 根据输入字段检索职位时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38808295/

相关文章:

api - Binance API 如何在 24 小时内计算 priceChangePercent

java - 将 Long 数组传递给 JSNI 函数

javascript - 在可编辑内容的表行上按 ENTER 单击调用 jQuery focusout

html - 在一行中实现显示卡

iphone - 如何为移动应用程序设计安全的 API/身份验证以访问服务?

javascript - 谷歌分析 API Javascript : 403 Forbidden Error

javascript - JQuery.TextnTags 插件不工作

javascript - Highmaps 中可以使用 "value"以外的其他列名吗?

javascript - 通过 JavaScript 选择文本

html - 如何仅在 CSS 中制作此箭头?