[英]Connecting to WCF service using AJAX in jQuery
I'm trying to connect to simple wcf
service locally, but every time I get some errors. 我试图在本地连接到简单的
wcf
服务,但是每次遇到错误时,我都会尝试连接。 This is my WCF
: 这是我的
WCF
:
public class Service1 : IService1
{
[OperationContract]
[WebInvoke(Method = "POST")]
public int square(int number)
{
var res = number * number;
return res;
}
}
And this is AJAX
part : 这是
AJAX
一部分:
$.ajax({
url: 'http://localhost:9247/Service1.svc/square',
method: 'POST',
contentType: 'application/json ;charset=utf-8',
data: { number: number },
dataType: 'json',
success: function (data) {
console.log(data);
$('#Result').val(data.d.res);
},
error: function (err) {
console.log(err);
}
});
});
What's wrong ? 怎么了 ? Can anybody explain me ?
有人可以向我解释吗?
Try this.. hope its helpfull for you 试试这个..希望对您有帮助
http://www.c-sharpcorner.com/UploadFile/rohatash/calling-wcf-services-using-jquery/ http://www.c-sharpcorner.com/UploadFile/rohatash/calling-wcf-services-using-jquery/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.