gpt4 book ai didi

javascript - jquery live 和通过 wcf 服务的回调

转载 作者:行者123 更新时间:2023-12-02 20:39:53 25 4
gpt4 key购买 nike

我正在使用 asp.net、c# 和 jquery 编写一个网络应用程序。大多数时候,我将动态 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,但他们在这里造成了严重破坏!

小伙伴们,你们有线索吗?

最佳答案

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

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

编辑:更新答案

关于javascript - jquery live 和通过 wcf 服务的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2679008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com