梅西产品 API jQuery

Macy product API jQuery

我是一名初级程序员,试图根据我的关键字URL 来获取 macy 产品信息,这里:http://developer.macys.com/docs/read/catalog_and_store_services/catalog/search#requesturl
它们有 3 个强制参数,其中 2 个在 HTTP header、Acceptx-macys-webservice-client-id 中,另一个在查询参数 searchphrase 中。 根据文档,我形成了一个jQuery函数来获取产品信息:

function ajaxsearch(){
    var terms = "reddress";
    var macyurl = "https://api.macys.com/v4/catalog/search?searchphrase="+ terms;
    alert(macyurl);
    var apikey = "6zjre5gv8822t323e6wxj85a";
     $.ajax({
        url: macyurl,
        headers:{
        Accept: application/json,
        x-macys-webservice-client-id: apikey
        }
        success: function(data){
        alert("successful call!") 

        }

    });

}

问题:我的函数语法正确吗?我已经用控制台检查过这个,他们遇到了 headers,x-macys-webservice-client-id 之一的问题。在我的案例中,这是设置 HTTP header 参数的正确方法吗?

对象的键应该遵循与变量命名相同的规则。如果不是,他们应该这样引用:

headers:{
    Accept: "application/json", // you can quote the key here too, but the value has to be quoted.
    "x-macys-webservice-client-id": apikey // the key must be quoted since - aren't allowed in key names. if apikey is not a variable, then it should be quoted too.
}, // Plus, you forgot to put a comma here to separate the entries

注意:如果您不知道 keysvalues 是什么意思,这就是我所说的:

{
    key: value,
    anotherKey: anotherValue,
    // ...
}