无法使用jQuery显示来自AJAX调用JSON数据的数据

无法使用jQuery显示来自AJAX调用JSON数据的数据,jquery,ajax,Jquery,Ajax,真的很困惑,所以帮助会很好 我正试图从求职API查看JSON数据 下面的查询(必须删除访问密钥) })) 这是它应该返回的数据 { "jobs": [ { "agency": { "title": "BCT Resourcing", "type": "Recruitment Agency", "url": "https://www.cv-library.co.uk/list-jobs/289229/BC

真的很困惑,所以帮助会很好

我正试图从求职API查看JSON数据

下面的查询(必须删除访问密钥)

}))

这是它应该返回的数据

{
"jobs": [
   {
        "agency": {
            "title": "BCT Resourcing",
            "type": "Recruitment Agency",
            "url": "https://www.cv-library.co.uk/list-jobs/289229/BCT-Resourcing"
        },
        "applications": "<10",
        "description": "Position: Automation & Monitoring Engineers\nLocation: Hampshire\nSalary: \u00a340000- \u00a355000 Per Annum\nJob type: Permanent\n\nDescription\n Candidates must have lived in the UK for 5 years minimum in order to achieve the security clearance required for this role.\n \nOur client work with a number of exciting and often cutting-edge technologies in a fast-moving environment.  With this environment, great automation and monitoring delivers huge value in both pace and accuracy for our team and Customers, in turn increasing our capability.  Our team are responsible for the management platform, tools and systems to automate, manage and monitor infrastructure",
        "distance": 3,
        "hl_title": "Automation & Monitoring Engineers",
        "id": "205765440",
        "location": "Farnborough",
        "logo": "https://www.cv-library.co.uk/logo/big/bac0998768784a75beea9b928d5c8c89",
        "posted": "2017-04-26T10:31:27Z",
        "salary": "\u00a340000 - \u00a355000/annum",
        "title": "Automation & Monitoring Engineers",
        "type": [
            "Permanent"
        ],
        "url": "/job/205765440/Automation-Monitoring-Engineers?hlkw=Perl&s=101081"
    }
],
"total_entries": 13
{
“工作”:[
{
“机构”:{
“标题”:“BCT资源”,
“类型”:“招聘机构”,
“url”:”https://www.cv-library.co.uk/list-jobs/289229/BCT-Resourcing"
},

“应用程序”:“请尝试下面的内容。如果出现相同的错误,请检查JSON是否有效

success: function(data) {
    var res = $.parseJSON(data);
    $.each(res.jobs, function(i, val) {
        $("#joblist").append(document.createTextNode(val.title));
        $("#joblist").append(document.createTextNode(val.logo));
    });
}

要将参数传递到
url
,您需要使用
$.ajax()
函数的
数据
参数

从您的
url
,远程设备使用的方法似乎是
GET
,因此此代码应该可以工作:

var myData = encodeURIComponent("key=YourKey&query=Support&geo=London&distance=200&tempperm=Part Time");
$.ajax({
 type: "GET",
 url: "https://www.cv-library.co.uk/search-jobs-json",
 data = myData,
 success: function(data)
 {
    console.log(data);

    $.each(data.results, function(i, val) {
        // here you can do your magic
        $("#joblist").append(document.createTextNode(val.title));
        $("#joblist").append(document.createTextNode(val.logo));
    });
 }

});
编辑: 从下面的注释中,返回的数据如下所示
{jobs:Array(25),total_entries:220},因此要循环作业,需要执行以下操作:

$.each(data.jobs, function(i, val) {
    $("#joblist").append(document.createTextNode(val.agency.title));
    $("#joblist").append(document.createTextNode(val.logo));
});

我假设
key、query、geo、distance、tempperm
是传递到
URL
的参数?是的,尽管只需要key&q就可以生成结果
tempperm:['兼职','永久']中的
是否安全.
是无意的,在您的源代码中确实是一个
?下次您遇到AJAX调用问题时,请确保在研究响应结构时仔细检查传出请求的结构!这很奇怪,因为它在控制台窗口{jobs:Array(25),total_entries:220}中显示数据您正在执行
$。每个(data.results
但是返回的数据不包含任何名称为
results
的内容。我已经用一个部分编辑了答案,以循环作业列表。希望有帮助。发现了它。。将结果替换为作业。。工作很好!谢谢
$.each(data.jobs, function(i, val) {
    $("#joblist").append(document.createTextNode(val.agency.title));
    $("#joblist").append(document.createTextNode(val.logo));
});