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
After Insert the record at index.aspx page redirect to ajax
Dec 25 2018 2:39 AM
After Insert the record at index.aspx page redirect to ajax success function and show the message alert("success"); I wrote function addProject() to do the task.i didn't get any error. record is added successfully in the database. but alert("success") message is not displayed.i tried the code below
error displayed an object reference is required for non-static field,method error was displayed
this lines get error
string fname = Request.Form["fname"];
string age = Request.Form["age"]
public static string doSomething(int id)
{
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();
con.Close();
return "Sucess";
}
Ajax
function addProject() {
$.ajax({
type: 'POST',
url: 'insert.aspx/doSomething',
dataType: 'JSON',
data: {fname: $('#fname').val(), age: $('#age').val()},
success: function (data) {
alert("success");
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
}
});
}
Reply
Answers (
2
)
Record is added in to the database but alert message is not
How to send data frm api to contrller Asp.net MVC using ajax