2016-08-06 7 views
0

Ich habe versucht, die API von Indeed.com zu verwenden, um ortsabhängige Jobs zu suchen. Ich jedoch halten auf den Fehler immer sagen, dassFehler beim Versuch, die Independent-API zum Abrufen des Jobs anhand des Eingabefelds zu verwenden

https://ip-api.com/json/?callback=jQuery2140044062367054279905_1470512340351&_=1470512340352 fehlgeschlagen Ressource laden: net :: ERR_CONNECTION_REFUSED

Dies ist der Code, den ich habe:

<!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> 

Jede Hilfe ist willkommen!

Antwort

Verwandte Themen