0

我越来越

XMLHttpRequest 无法加载http://myurl.com/RestServiceImpl.svc/post。Access-Control-Allow-Origin 不允许来源http://myurl2.com 。我的客户端 Javascript 应用程序中的此错误在调用用 WCF Rest 编写的 Post 服务时

我的服务

[OperationContract]
        [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "post")]
        bool JSONDataPost(string Value);


public bool JSONDataPost(string Value)
        {   //code to Create the Person goes here

            return true;
        }

我的客户要求是

var xhr = new XMLHttpRequest();
    xhr.open('POST', 'http://myurl.com/RestServiceImpl.svc/post', true);
    xhr.setRequestHeader("Content-Type", "application/jsonp;charset=UTF-8");
    xhr.onload = function () {
        // do something to response

    console.log(this.responseText);
    };
    xhr.send(JSON.stringify("TEST"));
4

0 回答 0