简单的Ajax不工作 [英] Simple AJAX not working

查看:145
本文介绍了简单的Ajax不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的AJAX code,但它似乎并没有抛出警告的方法。相反,没有任何反应。我看着它的提琴手和得到这个错误信息: {消息:有一个错误处理请求,堆栈跟踪:,ExceptionType:}

I have this AJAX code, but it doesn't seem to throw the 'alert' method. Instead, nothing happens. I looked at it with Fiddler and got this error message: {"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

我想打电话给在code-后面称为Web方法 MyWebMethod

I'm trying to call a web method in the code-behind called MyWebMethod:

 $.ajax({   type: "POST",
            url: "Test.aspx/MyWebMethod",
            data: "{" + username + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",

            success: function() {
                alert("success");
            },

            fail: function() {
                alert("Fail");
            }
 });

Web方法工作得很好,当我有在页面上的脚本经理,但我想删除脚本经理,认为使用AJAX将是最好的方式。

The web method worked fine when I had a script manager on the page, but I want to remove the script manager and thought that using AJAX would be the best way.

感谢

推荐答案

我认为,如果你改变失败错误,你会得到第二次警告框。

I think if you change fail to error, you'll get the second alert box.

我想,如果你再改

data: "{" + username + "}"

data: "{ 'username': '" + username + "' }"

你会得到第一个警报,但很难​​知道,没有看到该服务你打电话。

you'll get the first alert, although it's hard to know that without seeing the service you're calling.

这篇关于简单的Ajax不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆