Calling WCF service from jQuery with Ajax,but the parameters are'nt passed.(ASP.NET) -


i'm developing microsoft visual studio 2013 community edition (webforms,visual basic).

in jquery script,calling wcf service ajax.

when press button 'loginme' , in "function fnverifyid (byval id string, byval pass string) ", "id" , "pass" 'nothing'.(i saw in firefox debugger.)

but insted of "para",in case using "data: { id: "testid", pass: "testpass" }" (in comment),the parameter passed expected ,for reason.

【test.aspx】

<%@ page title="" language="vb" autoeventwireup="false"     masterpagefile="~/site.mobile.master" codebehind="test.aspx.vb" inherits="shop.daishin" %>     <%--<asp:content id="content1" contentplaceholderid="headcontent" runat="server"> </asp:content> <asp:content id="content2" contentplaceholderid="featuredcontent" runat="server"> </asp:content>--%> <asp:content id="content3" contentplaceholderid="maincontent" runat="server">  <head>     <!doctype html>  <title>test title</title> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css"/> <link rel="stylesheet" href="css/custom.css"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>     <%--<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>--%> <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> <script src="js/jcarousel.min.js" type="application/x-javascript" charset="utf-8"></script> <script src="js/custom.js"></script>       <script type="text/javascript">      $(function () {          $('#loginme').click(function () {              var para = '{id: ' +  '"'+ $('#txtusername').val() +'"'+ ', pass: ' + '"'+ $('#txtpassword').val() + '"}'              $.ajax({                 url: '/testwcf.svc/fnverifyid',                   datatype: 'json',                  contenttype: "application/json; charset=utf-8",                  //data: { id: "testid", pass: "testpass" },    // ok.                 data: para,                  success: function (response) {                         var obj = json.parse(response.d);                                     alert(obj.name)                 },                   error: function (xhr, status, err) {                     alert('exeption:');                  }              });          });     });  </script>  </head> <body>    <div data-role="page" data-add-back-btn="true" id="p-listview-thumbnail" >          <div data-role="header" data-position="fixed" data-theme="d">            <h1></h1>             <a href="#family" data-icon="gear" class="ui-btn-right" data-iconpos="notext" data-theme="d" >options</a>                <input type="text" id="txtusername" placeholder="username" />             <input type="password" name="passwordinput" id="txtpassword"  placeholder="password" value=""  />             <a href="javascript:authenticate();" id="loginme" data-role="button" data-icon="check" data-iconpos="right">log me in!</a>              <label for="basic_name" id="lblmessage"></label>                     </div><!-- /content -->  </body> </html> 

【testwcf.svc】

imports system.servicemodel imports system.servicemodel.activation imports system.servicemodel.web imports system.web.providers.entities imports system.runtime.serialization.json imports system.servicemodel.description imports system.runtime.serialization imports newtonsoft.json  <servicecontract()> public interface iservice1      <operationcontract()> _         <webinvoke(method:="get", responseformat:=webmessageformat.json)> _     function fnverifyid(byval id string, byval pass string)  end interface <datacontract()> _ public class csverifyid     dim sid string     dim iflg integer     dim sname string       <datamember()> _     public property name() string                     return sname         end         set(value string)             sname = value         end set     end property  end class  <servicecontract(namespace:="")> _ <aspnetcompatibilityrequirements(requirementsmode:=aspnetcompatibilityrequirementsmode.allowed)> public class daishinwcf       <webget()>     public function fnverifyid(byval id string, byval pass string)          dim hyouji string = cstr(id) & cstr(pass)          dim objveryfyid new csverifyid          objveryfyid.name = "name"          dim person string = jsonconvert.serializeobject(objveryfyid)          return person      end function     <operationcontract()>     public sub dowork()         ' add operation implementation here     end sub  end class 

try this:

var jdata = {}; jdata.id = $('#txtusername').val(); jdata.pass = $('#txtpassword').val(); $.ajax({     crossdomain: true,     cache: false,     url: '/testwcf.svc/fnverifyid',     contenttype: "application/json; charset=utf-8",     datatype: "json",     data: json.stringify(jdata),     success: successrslt,     error: function (xhr, reason, ex) {         var err = $.parsejson(xhr.responsetext);         if (err != null && xhr.status.tostring() != "0") {             showerror('error code : ' + xhr.status + "\nerror message :" + xhr.statustext);         }     } }); 

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 -