问题
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