Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function saveData() {

            var txtName = $("#txtName").val();
            var txtEmailId = $("#txtEmailId").val();
            var txtPwd = $("#txtPwd").val();
            var txtPhoneNo = $("#txtPhoneNo").val();
            $.ajax({
                type: "POST",
                url: "http://microsoft.com/webserviceswithdatabase/saveData",
                data: "{Name:'" + txtName + "',Password:'" + txtPwd + "',EmailID:'" + txtEmailId + "',PhoneNo:'" + txtPhoneNo + "'}",
                contentType: "application/json; charset=utf-8",
                datatype: "jsondata",
                async: "true",
                success: function (response) {
                   // $(".errMsg ul").remove();
                    var myObject = eval('(' + response.d + ')');
                    if (myObject > 0) {
                        // bindData();
                        alert(" saved successfully");

                    }
                    else {
                          alert("Opppps something went wrong.");
                    }
                   // $(".errMsg").show("slow");
                    clear();
                },
                error: function (response) {
                    alert(response.status + ' ' + response.statusText);
                }
            });

        }

when i run this code, i got 0 error message. So please tell me how to solve this?
Posted
Comments
Member 10448952 8-Jan-15 3:29am    
is anybody there? please help me to solve this problem.
Thanks in advance.
Nathan Minier 8-Jan-15 7:39am    
Well, for starters your data field is malformed, that should be a JSON object, not a string.
data: {Name: txtName, Password: txtPwd, emailID: txtEmailId, PhoneNo: txtPhoneNo};

Secondly, "jsondata" is not a valid return type. You can either omit that field, or change it to datatype: "json"

Third, make sure that the value 'd' in the returned data is well-formed javascript that returns a value, because otherwise var myObject = eval('(' + response.d + ')') will just be null.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900