TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kobinath Ram
NA
130
0
Record is added in to the database but alert message is not
Dec 24 2018 6:44 AM
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"
)
}
Reply
Answers (
3
)
Autocompleteextender not working
After Insert the record at index.aspx page redirect to ajax