I want to achieve create (INSERT) screen using $.POST or $.AJAX.
Note: code is working fine without AJAX call..it is already there.. now i need to do ajax call and s
If the id of your form is frm
, then it should be referenced as follows
data: $("#frm").serialize(),
For id Selector you have to use "#" with id.
This will work :
$.ajax(
{
url: '@Url.Action("CreateProduct","ProductManagement")',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'post',
data: $('this').serialize(), OR $('#frm').serialize(), <-----------------
success: function () { alert('s'); },
error: function (e1, e2, e3) { alert(e2); alert(e1 + ' ' + e2 + ' ' + e3); alert('failure event'); }
}
);
OR Try this :
var form = $('#frm');
$.ajax({
cache: false,
async: true,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: "POST",
url: form.attr('action'),
data: form.serialize(),
success: function (data) {
alert(data);
}
});
You have forgot to add id selecter:
$.ajax(
{
url: '@Url.Action("CreateProduct","ProductManagement")',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'post',
data: $('#frm').serialize(), // $('#frm');
success: function () { alert('s'); },
error: function (e1, e2, e3) { alert(e2); alert(e1 + ' ' + e2 + ' ' + e3); alert('failure event'); }
}
);