sending custom object from client (Jquery) to server (WCF)

纵饮孤独 提交于 2019-12-10 10:57:45

问题


how to send a custom object from client (jquery) to server (WCF service)

what is the way of passing an object? below is my code and when i see in the firebug this is what i get please see the screen shot: http://img88.imageshack.us/img88/205/54211873.png

var CustomerInfo = {
                Name: '',
                Address: ''
            };

            function buildNewCustomerRequest() {
                var request = {
                    CustomerInfo: CustomerInfo
                };
                request.CustomerInfo.FirstName = $("#Name").val();
                request.CustomerInfo.Address = $("#Address").val(); 

                return request;
            }



     $("#getcustomerobject").click(function (event) {
                    var request = buildNewCustomerRequest();
                     var json = JSON.stringify(request);
                    $.getJSON('http://host/MyService.svc/GetCusto
merObject?CustomerObject=?', { request: json }, function (customer) {

                        //
                    });
                });

 <li>
            <label id="lblFirstName" for="Name">
              First Name :
            </label>
            <input id="Name" name="Name" type="text" maxlength="25" class="required" />  </li>
          <li>
            <label id="lbllastName" for="Address">
              Address :
            </label>
            <input id="Address" name="Address" type="text" maxlength="25" class="required" /><em> </li>
          <li>

here is my WCF service looks like:

public bool GetCustomerObject(string method, Customer customer)
        {
            if (customer.Name == "test")
                return true;
            return false;
        }

来源:https://stackoverflow.com/questions/4236047/sending-custom-object-from-client-jquery-to-server-wcf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!