c# - Call Web Service from jquery Ajax -


i have tried call webservice method using ajax in asp.net. web service method.

[webmethod] public string registerws(string email, string firstname, string lastname, string address, string mobile) {     string query = "insertcrud_sp";     sqlcommand com = new sqlcommand(query, con);     com.commandtype = commandtype.storedprocedure;     string res = "";     com.parameters.addwithvalue("@email", email);     com.parameters.addwithvalue("@firstname", firstname);     com.parameters.addwithvalue("@lastname", lastname);     com.parameters.addwithvalue("@address", address);     com.parameters.addwithvalue("@mobile", mobile);     con.open();         if (com.executenonquery() > 0)         {             con.close();             res= "true";         }         else         {             con.close();             res= "false";         }     return res; } 

this jquery code..

$(document).on("click","#btnajaxcontrol", function () {     var mail = document.getelementbyid("txtmail").value;     var fname = document.getelementbyid("txtfname").value;     var lname = document.getelementbyid("txtlname").value;     var addr = document.getelementbyid("txtaddress").value;     var mobile = document.getelementbyid("txtmobile").value;     if (validateemail(mail) && !(mail == "") && !(fname == "") && !(lname == "") && !(addr == "") && !(mobile == "")) {         $.ajax({             type: "post",             contenttype: "application/json; charset=utf-8",             url: "crudwebservicejs.asmx/registerws",             data: { 'email': mail, 'firstname': fname, 'lastname': lname, 'address': addr, 'mobile': mobile },             cache: false,             success: function (data) {                 var wsres = data.d;                 if (wsres == 'true') {                     $('#lblmsg').html('user registered...');                 }             },             error: function (result) {                 alert(result);                 $('#lblmsg').html('user registeration faild...!');                 $("#lblmsg").css('background', 'red');             }         });     } }); 

web service method works alone... when calling web service ajax error message invoked... don't know whats wrong code.. please me find out error in program , suggest need change.... in advanced....


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -