如何从客户端(jquery)向服务器(WCF服务)发送自定义对象
传递对象的方式是什么?下面是我的代码,当我在firebug中看到这是我得到的,请看屏幕截图: 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>
这是我的WCF服务,如下所示:
public bool GetCustomerObject(string method, Customer customer)
{
if (customer.Name == "test")
return true;
return false;
}