jquery ajax调用没有打到c#webmethod。点击页面加载。

时间:2016-02-20 01:09:26

标签: javascript c# jquery ajax

我无法弄清楚为什么我的Javascript ajax调用无法点击我的c#方法。我在后面的代码中构建了这个。



ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", @"swal.withForm({
                        title: 'Database Credentials',
                        formFields: [{
                            id: 'server',
                            placeholder: 'Server Name'
                        }, {
                            id: 'username',
                            placeholder: 'User Name'
                        }, {
                            id: 'password',
                            placeholder: 'Password',
                            type: 'password'
                        }, {
                            id: 'databaseName',
                            placeholder: 'Database Name'
                        }],
                        html: true,
                        confirmButtonText: 'Update'
                    }, function(isConfirm) {
                        console.log(JSON.stringify(this.swalForm));
                        $.ajax({
                            type: 'GET',
                            url: 'WebMethods.aspx/CheckCreateDatabase',
                            contentType: 'application / json; charset = utf - 8',
                            dataType: 'html',
                            data: JSON.stringify(this.swalForm),
                            success: function(data) {
                                swal('Success ' + data);
                            },
                            error: function(data, success, error) {
                                swal('Error ' + error);
                            }
                        });
                    });", true);




控制台根据我的输入输出json字符串的结果。

{"server":"dfd","username":"df","password":"dfd","databaseName":"dfd"}

我的代码

    public partial class WebMethods : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var a = "a";    
    }

[WebMethod]
    public static string CheckCreateDatabase(string server, string username, string password, string databaseName)
    {
        return "it worked";
    }
}

它将在页面加载事件中达到我的断点,但它不会在CheckCreateDatabase块中命中它。

我尝试了很多不同的帖子但仍然无法使用该方法。 有没有人看到任何错误或我可以研究的任何事情。谢谢。

0 个答案:

没有答案