简体   繁体   English

向此组合框添加AJAX调用以读取JSON

[英]Adding an AJAX call to this Combobox to read through JSON

I'm having problems adding a XHR request to query JSON to my script, I rarely work with either so it's giving me a lot of problems. 我在向脚本中添加XHR请求以查询JSON时遇到问题,我很少使用这两者,因此这给我带来了很多问题。 I know that I will need to query a JS file, and that I will need to select from matches in an array, but I am completely stumped on how to do it. 我知道我将需要查询JS文件,并且需要从数组中的匹配项中进行选择,但是我完全迷住了如何执行此操作。 Something else I need to do is count matches each time I fire of a request. 我需要做的其他事情是每次触发请求时都计算匹配项。

The categories startList is what I am using now, it's not really filled in but I was just trying to get it to work first before I started using JSON. startList类别是我现在正在使用的类别,它实际上并没有填写,但是我只是想让它在开始使用JSON之前首先起作用。 Can anyone help me here? 有人能帮我一下吗?

var categories = [];

categories["startList"]                 = ["Men","Women"]
    categories["Men"]                   = ["Red","Blue","Multi"];
        categories["Red"]               = ["Leather","Metal","Ceramic","Plastic"];
            categories["Leather"]               = ["",""];
            categories["Metal"]                 = ["",""];
            categories["Ceramic"]               = ["",""];
            categories["Plastic"]               = ["",""];
        categories["Blue"]              = ["This","That","Neither"];
        categories["Multi"]             = ["One","Two","Other"];

    categories["Women"]                 = ["Green","Hot Pink","Multi"];
        categories["Green"]             = ["Them","Those","Moo"];
        categories["Hot Pink"]          = ["The","Quick","Brown"];
        categories["Multi"]             = ["Three","Four","Other"];



var nLists = 6; 

function fillSelect(currCat,currList){
var step = Number(currList.name.replace(/\D/g,""));
for (i=step; i

Here is a quick sample of one of the JSON fields I will want to query.

{ "idName": "The Time Teller", "forGender": "m", "caseDiameter": 1.5, "caseThickness": 0.5, "bandWidth": 0.78, "itemWeight": 1.44,{ "sku": 155320,{ "color1": "white", "color2": "none", "price": 59.99, "cat": "29400", "img": "155320-0002-front", "sku": 155411,{ "color1": "blue", "color2": "none", "price": 59.99, "cat": "32579", "img": "155411-0005-front", "sku": 160041,{ "color1": "black", "color2": "pink", "price": 59.99, "cat": "38404", "img": "160041-0001-front", }, "specialInformation": [ { "restrictions": "Available for US customers only." "detail": "Custom 3 hand Japanese quartz movement.", "detail": "100 meter molded polycarbonate case.", "detail": "Hardened mineral crystal.", "detail": "Locking looper and polycarbonate buckle.", }, { "desc": "Nixon's The Time Teller watch keeps it simpleton with hard case and custom molded polyurethane band."' } ] }

You have wrong JSON data. 您的JSON数据错误。 For example the blocks like 例如像

{ "color1": "white",  "color2": "none", "price": 59.99,
  "cat": "29400",     "img": "155320-0002-front",

should be replaced to 应该替换为

{ "color1": "white",  "color2": "none", "price": 59.99,
  "cat": "29400",     "img": "155320-0002-front" },

But it in not all errors. 但这并不是所有的错误。 I recommend you verify your JSON data in http://www.jsonlint.com/ . 我建议您在http://www.jsonlint.com/中验证JSON数据。 On http://www.json.org/ you will fnd the description of JSON format. http://www.json.org/上,您将找到JSON格式的描述。

Here is an example of a possible correct JSON data 这是一个可能的正确JSON数据的示例

{
    "idName": "The Time Teller",
    "forGender": "m",
    "caseDiameter": 1.5,
    "caseThickness": 0.5,
    "bandWidth": 0.78,
    "itemWeight": 1.44,
    "items": [
        {
            "color1": "white",
            "color2": "none",
            "price": 59.99,
            "cat": "29400",
            "img": "155320-0002-front",
            "sku": 155411 
        },
        {
            "color1": "blue",
            "color2": "none",
            "price": 59.99,
            "cat": "32579",
            "img": "155411-0005-front",
            "sku": 160041 
        },
        {
            "color1": "black",
            "color2": "pink",
            "price": 59.99,
            "cat": "38404",
            "img": "160041-0001-front",
            "sku": 155320 
        } 
    ],
    "specialInformation": {
        "restrictions": "Available for US customers only.",
        "details": [
            "Custom 3 hand Japanese quartz movement.",
            "100 meter molded polycarbonate case.",
            "Hardened mineral crystal.",
            "Locking looper and polycarbonate buckle." 
        ],
        "desc": "Nixon's The Time Teller watch keeps it simpleton with hard case and custom molded polyurethane band." 
    } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM