i have 1 project webservice and 1 project web asp.net i want to insert data by json(ajax) i tested file service by code behind and it good, have error with code js file WebService1:

public bool HelloWorld(student obj)
        SqlConnection cnn = new SqlConnection("Data Source=PHAMHOP-LAPTOP\\SQLEXPRESS;Initial Catalog=qlsv;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("insert into sinhvien(name,age) values(@name,@age)", cnn);
        cmd.Parameters.AddWithValue("name", obj.name);
        cmd.Parameters.AddWithValue("age", obj.age);
        int row = cmd.ExecuteNonQuery();
        if (row == 1)
            return true;
            return false;

file aspx:

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function add() {

                type: "POST",
                url: "http://localhost:51097/Service1.asmx/HelloWorld",
                data: "{'id':'1' ,'name': 'Amit', 'age': '97'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
<body><input type='Button' value='gui' OnClick='add()'/></body>

It does not work.

Related posts

Recent Viewed