代码之家  ›  专栏  ›  技术社区  ›  vondip

通过wcf服务进行jquery实时和回调

  •  0
  • vondip  · 技术社区  · 15 年前

    我正在用ASP.NET、C和JQuery编写一个Web应用程序。 大多数时候,我都在向浏览器编写动态HTML,并使用不同的Web服务来获取所需的内容。

    我的服务电话:

    function WriteProducts(currentIndex, selectedCategoryId, callback) {
        var d = new Date();
        MyAppServices.GetProducts(selectedCategoryId, currentIndex, 8,
            d.getTime().toString(), callback, function func() {
                 alert('failure'); 
            });
    }
    

    请求通常被转换成这个(使用我监视的Firebug):

    http://localhost:8080/MyApp/MyAppServices.svc/GetProducts?categoryId=0&fromIndex=0&toIndex=8&randomNumber=%221271800014441%22
    

    当动态呈现的HTML控件的一部分需要响应单击事件时,问题就开始了。当我开始使用jquery的live方法时:

    $('.filter').live('click', function(event) {
        WriteProducts(0, selectedCategoryId, PopulateDivs);
    });
    

    现在出于某种原因,传递给服务器的请求变成了:

    http://localhost:8080/MyApp/MyAppServices.svc/GetProducts?categoryId=**%2217%22**&fromIndex=0&toIndex=8&randomNumber=%221271799783355%22
    

    这些%22是从哪里来的?如果我把它们取出来,请求就成功地通过了。 我不知道是谁插入了这%22,但它们在这里造成了严重的破坏!

    伙计们,你们有什么线索吗?

    2 回复  |  直到 15 年前
        1
  •  1
  •   Mottie    15 年前

    可能需要将日期字符串转换为数字。脚本似乎正在字符串周围添加引号。所以试试这个:

    function WriteProducts(currentIndex, selectedCategoryId, callback) {
        var d = new Date().getTime();
        MyAppServices.GetProducts(selectedCategoryId, currentIndex, 8,
            d, callback, function func() {
                 alert('failure'); 
            });
    }
    

    编辑:更新了答案

        2
  •  1
  •   Sean Kinsey    15 年前

    %22与“相同,所以我猜变量 selectedCategoryId 实际上是一个值为“17”的字符串。

    尝试设置断点并检查该值。

    很难得出结论,因为您没有包含所有相关的代码。