【问题标题】:Connecting to WCF service using AJAX in jQuery在 jQuery 中使用 AJAX 连接到 WCF 服务
【发布时间】:2016-12-16 08:19:25
【问题描述】:

我正在尝试在本地连接到简单的wcf 服务,但每次我都会遇到一些错误。 这是我的WCF

public class Service1 : IService1
{

    [OperationContract]
    [WebInvoke(Method = "POST")]
    public int square(int number)
    {
        var res = number * number;
        return res;
    }

}

这是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);
                }
            });
        });

怎么了?有人可以解释一下吗?

【问题讨论】:

  • "每次我遇到一些错误" Errrr,如果您告诉我们您看到什么错误消息...可能会对我们有所帮助...?
  • 对象 {readyState: 0, responseJSON: undefined, status: 0, statusText: "error"}

标签: jquery ajax web-services wcf


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 2014-07-08
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多