将自定义对象从客户端 (Jquery) 发送到服务器 (WCF)
如何将自定义对象从客户端(jquery)发送到服务器(WCF服务)
传递对象的方式是什么?下面是我的代码,当我在萤火虫中看到时,这就是我得到的,请查看屏幕截图: 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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论