Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 韩元';按价格/挂牌类型筛选易趣API结果_Javascript_Html_Json_Ebay Api - Fatal编程技术网

Javascript 韩元';按价格/挂牌类型筛选易趣API结果

Javascript 韩元';按价格/挂牌类型筛选易趣API结果,javascript,html,json,ebay-api,Javascript,Html,Json,Ebay Api,在遵循易趣的API准则显示在指定价格范围内的固定价格物品后,结果仍然显示在该范围之外的基于拍卖的不同价格物品。我逐字逐句地听了他们的教程,所以我不确定我做错了什么 代码: <div id="api"></div> <script> function _cb_findItemsByKeywords(root) { var items = root.findItemsByKeywordsResponse[0].searchResult[0].item ||

在遵循易趣的API准则显示在指定价格范围内的固定价格物品后,结果仍然显示在该范围之外的基于拍卖的不同价格物品。我逐字逐句地听了他们的教程,所以我不确定我做错了什么

代码:

<div id="api"></div>

<script>
function _cb_findItemsByKeywords(root)
{
  var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
  var html = [];
  html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');

  for (var i = 0; i < items.length; ++i)  
  {
    var item     = items[i];
    var title    = item.title;
    var pic      = item.galleryURL;
    var viewitem = item.viewItemURL;
    if (null != title && null != viewitem)
    {
      html.push(
        '<tr id="api_microposts"><td>'
         + '<img src="' + pic + '" border="0" width="190">' + '<a href="' + viewitem + '" target="_blank">' + title + 
         '</a></td></tr>');
    }
  }
  html.push('</tbody></table>');
  document.getElementById("api").innerHTML = html.join("");

// Create a JavaScript array of the item filters you want to use in your request
var filterarray = [
  {"name":"MaxPrice",
   "value":"500",
   "paramName":"Currency",
   "paramValue":"USD"},
   {"name":"MinPrice",
   "value":"200",
   "paramName":"Currency",
   "paramValue":"USD"},
  {"name":"FreeShippingOnly",
   "value":"true",
   "paramName":"",
   "paramValue":""},
  {"name":"ListingType",
   "value":["FixedPrice"],
   "paramName":"",
   "paramValue":""},
  ];


// Define global variable for the URL filter
var urlfilter = "";


// Generates an indexed URL snippet from the array of item filters
function  buildURLArray() {
  // Iterate through each filter in the array
  for(var i=0; i<filterarray.length; i++) {
    //Index each item filter in filterarray
    var itemfilter = filterarray[i];
    // Iterate through each parameter in each item filter
    for(var index in itemfilter) {
      // Check to see if the parameter has a value (some don't)
      if (itemfilter[index] !== "") {
        if (itemfilter[index] instanceof Array) {
          for(var r=0; r<itemfilter[index].length; r++) {
          var value = itemfilter[index][r];
          urlfilter += "&itemFilter\(" + i + "\)." + index + "\(" + r + "\)=" + value ;
          }
        }
        else {
          urlfilter += "&itemFilter\(" + i + "\)." + index + "=" + itemfilter[index];
        }
      }
    }
  }
}  // End buildURLArray() function

// Execute the function to build the URL filter
buildURLArray(filterarray);

url += urlfilter;



}
</script>


<!--
Use the value of your appid for the appid parameter below.
-->
<script src=http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=*App ID*&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&keywords=iphone%205%2016gb%20unlocked&paginationInput.entriesPerPage=3>
</script>

函数_cb_findItemsByKeywords(根)
{
var items=root.FindItemsByWordsResponse[0]。搜索结果[0]。项| |[];
var html=[];
html.push(“”);
对于(变量i=0;i对于(var i=0;i规范来自。我将分两步解决此问题:

检查是否得到相同的结果,即使您注释掉这一行:

    url += urlfilter;
如果发生这种情况,那么你的问题在于你提出请求的方式,而你设置的参数还不相关。如果它确实发生了变化,那么请求就进行得很顺利,你需要修改你传递的内容

在这种情况下,参数需要进行一些修改。如果您得到任何结果,则ListingType筛选器可能存在一个问题。规范规定ListingType接受一个字符串或可以接受多个值。可能是您希望使用:

    {"name":"ListingType",
    "value": "FixedPrice",
    "paramName":"",
    "paramValue":""}

即使使用了上面的语法,仍然会得到未过滤的结果。我将进一步查看规范,看看是否还有其他地方我可能做错了。