The alert message is not displayed after add record into the database using Asp.net Ajax.record is add into the database successfully.Alert is not displaying. I attached the code below what I tried so far below.after add record how to return to the ajax success function to display alert("success");
Form Design
- <form id="frmProject" runat="server">
- <div>
- <label class="form-label">First Name</label>
- <input type="text" id="fname" class="form-control" />
- </div>
- <div class="form-group" >
- <label class="form-label">Age</label>
- <input type="text" id="age" class="form-control" />
- </div>
- <div>
- <input type="button" id="b1" value="add" class="form-control" onclick="addProject()" />
- </div>
- </form>
Ajax
- function addProject() {
- $.ajax({
- type: 'POST',
- url: 'insert.aspx',
- dataType: 'JSON',
- data: {fname: $('#fname').val(), age: $('#age').val()},
- success: function (data) {
- alert("success");
- get_all();
- },
- error: function (xhr, status, error) {
- console.log(xhr.responseText);
- }
- });
- }
insert.aspx
- SqlConnection con = new SqlConnection("server=.; Initial Catalog = jds; Integrated Security= true;");
- protected void Page_Load(object sender, EventArgs e)
- {
- string fname = Request.Form["fname"];
- string age = Request.Form["age"];
- string sql = "insert into record values('" + fname + "','" + age+ "')";
- SqlCommand cmd = new SqlCommand(sql, con);
- con.Open();
- cmd.ExecuteNonQuery();
- Response.Write("success")
- }