jquery - Post data into database via ajax. displays 501 internal error -
i trying post data asp.net webform database. have in asp.net service (shoppingcart_service.asmx)
[webmethod] // public void registersubscriber(string email) { new onlineshoptableadapters.newslettersubscriberstableadapter().insert(email, datetime.now); //database code }
this html
<input type="button" onclick="savedata()" id="btnsave" value="subscribe" >
this ajax code, put in file called apps.js , linked page
//updated ! function savedata() {
function savedata() { var subscriberemail = $("#email").val(); $.ajax({ type: "post", url: "shoppingcart_service.asmx/registersubscriber", data: '{"email":"' + subscriberemail + '"}', contenttype: "application/json; charset=utf-8", datatype: "json", success: function (response) { alert(response.status + ' ' + response.statustext); }, error: function (request, status, error) { } }); }
but value doesn't posted database consider error got in chrome's console, after clicking subscribe button
i have done same thing in 1 of projects , works well..the difference can see webmethods return string/bool
values , webservice class has scriptservice
attribute.
see below:
[system.web.script.services.scriptservice] public class ajaxpost : webservice { [webmethod] public string callback(string txbfirstname) { } }
and script side is:
$.ajax({ type: "post", url: "/services/ajaxpost.asmx/callback", data: '{"txbfirstname":"' + txbfirstname + '"}', contenttype: "application/json; charset=utf-8", datatype: "json", success: function(result) { }, error: function(request, status, error) { } });
Comments
Post a Comment