The success function does not work in jQuery

I developed an application and in which i am inserting some records by using the service. The data is successfully inserted but the problem is my success function is not working.

$(document).ready(function () {
        $('#BtnRegister').click(function () {
            $.ajax({
                type: "POST",
                url: "DataService.svc/InsertData",
                data: '{ "Name": "' + $("#TxtUserName").val() + '", "Email" : "' + $("#TxtUserEmail").val() + '", "Category" : "' + $("#TxtUserCategory").val() + '", "Mobile" : "' + $("#TxtUserMobile").val() + '", "Message" : "' + $("#message").val() + '" }',
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    alert("data");
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) { alert('Loading Failed...'); }
            });
        });
    });

There is an alert message generated after inserting the data which generates from the error function. The data in inserted successfully. The error function is running every condition.

My InsertData Method:

public string InsertData(string Name, string Email, string Category, string Mobile, string Message)
    {
        string file = AppDomain.CurrentDomain.BaseDirectory + "\\DataFile.xml";             

        DataTable dtUser = ReadXML(file);

        DataRow dr = dtUser.NewRow();
        dr["Name"] = Name;
        dr["Email"] = Email;
        dr["Category"] = Category;
        dr["Mobile"] = Mobile;
        dr["Message"] = Message;
        dtUser.Rows.Add(dr);
        dtUser.WriteXml(file);
    }
$(document).ready(function () {
        $('#BtnRegister').click(function () {
                $.ajax({
                type: "POST",
                url: "DataService.svc/InsertData",
                data: '{ "Name": "' + $("#TxtUserName").val() + '", "Email" : "' + $("#TxtUserEmail").val() + '", "Category" : "' + $("#TxtUserCategory").val() + '", "Mobile" : "' + $("#TxtUserMobile").val() + '", "Message" : "' + $("#message").val() + '" }',
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                alert(result.d);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {   console.log('Loading Failed...'); }
            });
        });
    });
我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章