How to send data using Json and get in asp.net services -


i php developer , switched asp, want send data web services , there unable come solution. in php if want access data back-end process purpose use .serialize(); method,

for example:

<form id="loginform"> <input class="form-control" name="useremail" placeholder="email" type="email" required=""/> </form>

and in jscript function serialize form, e.g:

var data = $("#loginform").serialize(); 

and in process side can call inputs name, in asp.net unable same, might missing or asp.net not support such approach @ all? not know please programmers me out.

you should use id property , use stingify() method instead of serialization.

html

<input class="form-control" id="useremail" placeholder="email" type="email" required=""/> 

js

function yesfunction() {           var email= $("#useremail").val();          var d= [];         d.push(email);          var jsndta = json.stringify({ d: d});                     $.ajax({             type: "post",             url: "wbservices/searchschoolinfoandinventory.asmx/searchschoolbesicinfo",             data: jsndta,             contenttype: "application/json; charset=utf-8",             datatype: "json",             success: function (r) {                 var rtndata = r.d; //all returned data...                 var respdta = [];                 $.map(rtndata, function (item, index) {                     var j = [                         item.status,                         item.msg,                     ];                     respdta.push(j);                 });                 $.each(respdta, function (key, value) {                     var status = value[0];                     var msg = value[1];                       if (status == true) {                         table.html(msg);                     } else {                      }                 }); //1st out loop ends here...               },             error: function (jqxhr, textstatus, errorthrown) {                 //  $("#responsemovdetails").html(jqxhr + textstatus + errorthrown);                 alert("error while loading purchases head" + jqxhr + textstatus + errorthrown);              }            });      } 

now create class , create 2 public variables , call both variables creating class object in web service class.

    public class requestresponse     {         public bool status { get; set; }         public string msg { get; set; }     } [webmethod]         public list<requestresponse>activatepbudget(list<string> d)         {             requestresponse r = new requestresponse();             list<requestresponse> list = new list<requestresponse>();              string email= d[0].tostring();  //establish connection. have established connection in separate class.             dbcon dbcon = new dbcon();             string constr = dbcon.dbconnection();             sqlconnection con = new sqlconnection(constr);             try             {                 con.open();                 string checkemail = "select *  table_name email= @m";                 sqlcommand getcmd= new sqlcommand(checkemail,con);                 getcmd.parameters.addwithvalue("@m", email);                 sqldatareader reader=getbhidcmd.executereader();                  if(reader.read())                 {                     r.status = true;                     r.msg = "valid user or redirect user page";                     list.add(r);                 reader.close();                 }                 else                  {                  reader.close();                     r.status = false;                     r.msg = "invalid email";                     list.add(r);                  }              }             catch (exception ex)             {                 r.status = false;                 r.msg = "invalid email" + ex.tostring();                 list.add(r);             }                         {                 con.close();             }             return list;         } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -