0

我需要帮助在淘汰赛中提出 ajax 请求。这是我调用 webmethod 的 js 代码。

 // Client-side routes    
Sammy(function () {
    this.get('#:day', function() {
        self.choosenDateId(this.params.day);
        $.ajax({
            type: "POST",
            url: 'SinglePageApp.aspx/GetData',
            data: "{goalDate:'" + this.params.days + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                debugger;
                self.choosenDateGoal(msg.d);

                alert("success");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
                alert(errorThrown);
            }
        })
    });
}).run();

还有我用于绑定数据的 html

 <tbody data-bind="foreach: GetData">
            <tr data-bind="click: $root.goToGoal">
                <td data-bind="text: status"></td>
                <td data-bind="text: data"></td>
                <td data-bind="text: notes"></td>
            </tr>
        </tbody>

在我的 webemthod 中,我已将 day 作为参数传递。但无法调用 webmethod。请帮忙。

4

1 回答 1

0
Sammy(function () {
    this.get('#:day', function() {
        self.choosenDateId(this.params.day);
        $.get("SinglePageApp.aspx/GetData", { day: self.chosenDateId() }, self.choosenDateGoal);
    });
}).run();

我认为问题在于您this.params.day$.get通话中使用的事实。在那个函数中,我相信this是对 jQuery ajax XHR 上下文的引用,而不是Sammy上下文。

于 2012-10-01T14:32:04.933 回答