2009-07-06 52 views
1

这工作得很好:的getJSON回调查询字符串帕拉姆问题

  $.getJSON("http://localhost:59396/xxxWeb/ 
CarouselHandler.ashx?action=getproducts&ids=" + ids, 
       function(data) { 

        carousel.size(allProductIDs.length); 

        if (numberOfImagesLeftToShow < 
numberOfImagesToDisplay) { 
         first += (numberOfImagesToDisplay - 
numberOfImagesLeftToShow); 
        } 

        var d = 0; 
        for (var i = first; i <= last; i++) { 

         if (d != undefined) { 
          // add data using index of the array 
returned by JSON (which starts at 0) 
          carousel.add(i, decode(data[d].ImageTag)); 
         } 

         // set to last ProductID showing in Carousel 
         if (i == last) { lastProductID = parseFloat 
(data[d].ProductID); } 

         d++; 
        } 
       } 
      ); 

这是不行的,我没有得到任何图片尝试添加 &格式后呈现= JSON & jsoncallback =? :

  $.getJSON("http://localhost:59396/xxxWeb/ 
CarouselHandler.ashx?action=getproducts&ids=" + ids + 
"&format=json&jsoncallback=?", 
       function(data) { 

        carousel.size(allProductIDs.length); 

        if (numberOfImagesLeftToShow < 
numberOfImagesToDisplay) { 
         first += (numberOfImagesToDisplay - 
numberOfImagesLeftToShow); 
        } 

        var d = 0; 
        for (var i = first; i <= last; i++) { 

         if (d != undefined) { 
          // add data using index of the array 
returned by JSON (which starts at 0) 
          carousel.add(i, decode(data[d].ImageTag)); 
         } 

         // set to last ProductID showing in Carousel 
         if (i == last) { lastProductID = parseFloat 
(data[d].ProductID); } 

         d++; 
        } 
       } 
      ); 

同样在这里,调用我们的开发服务器。

$.getJSON("http://xxxdev/xxx/CarouselHandler.ashx? 
action=getproducts&ids=" + ids + "&format=json&jsoncallback=?", 
       function(data) { 

不知道为什么。没有错误,没有。接收到的数据与我在调用localhost时的第一个示例没有区别。所以这是有效的JSON,这不是问题在这里。这是我的函数(数据)没有被触发时,我介入查询字符串参数。没有它,它会正常工作,并调用函数(数据)。

添加“& jsoncallback =?”或“& callback =?”删除了访问 受限制的URI被拒绝的“代码:”1012,但当我的URL中添加了任何查询字符串参数时,我的 插件中没有显示数据。所以 我不明白。我以为它应该自动 替换?与函数(数据)在我的情况?我需要发送 东西回应什么?我问,因为某些 API(例如yahoo)需要前面的_。但这是否意味着我需要在我的json响应中提供某些东西?我认为你所需要做的只是在请求中添加回调参数。

回答

3

您的服务需要支持jsonp,这意味着响应必须被封装在回调键中以表示客户端执行的JavaScript函数。

作为总结,如果你的服务器有这个目前

{ "x": 10, "y": 15} 

响应支持JSONP它需要与

callbackFunction({ "x": 10, "y": 15}) 

其中callbackFunction参数是查询字符串指定的名称作出回应。

查看我的回答here了解更多信息