奇怪的问题;按钮点击,Jquery消费ASMX

发布于 2024-08-10 06:56:40 字数 740 浏览 5 评论 0原文

我遇到了一个非常令人沮丧的问题,我确信这个问题是微不足道的。每当我将这个 jQuery 帖子移动到点击函数中时,它有时会起作用,但大多数时候不会。 如果我将它移到外面,它就会工作并发布并给出每次都应有的响应。

::boggled:: 有人请启发我。

         $(document).ready(function() {
         $('#Button1').click(function() {

        //alert(document.getElementById('TextBox1').value);
        $.ajax({
            type: "POST",
            url: "sudoku.asmx/getSolution",
            data: "{'pid':'34367'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                alert("succes " + msg.d);
            },
            error: function(msg) {
                alert("fail " + msg.d);
            }
         });
        });
    }); 

I'm having quite a frustrating problem that I'm sure is TRIVIAL. Whenever I move this jQuery post inside the click function it sometimes works, but most of the time does not.
If I move it outside it works and posts and gives a response like it should everytime..

::boggled:: Someone please enlighten me.

         $(document).ready(function() {
         $('#Button1').click(function() {

        //alert(document.getElementById('TextBox1').value);
        $.ajax({
            type: "POST",
            url: "sudoku.asmx/getSolution",
            data: "{'pid':'34367'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                alert("succes " + msg.d);
            },
            error: function(msg) {
                alert("fail " + msg.d);
            }
         });
        });
    }); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惯饮孤独 2024-08-17 06:56:40

看起来您需要让点击事件返回 false。

$("#Button1").click(function()
{
    $.ajax(...);

    return false;
});

Looks like you need to have your click event return false.

$("#Button1").click(function()
{
    $.ajax(...);

    return false;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文