I'm Getting
XMLHttpRequest cannot load http://myurl.com/RestServiceImpl.svc/post. Origin http://myurl2.com is not allowed by Access-Control-Allow-Origin. This error in my client Javascript app While calling a Post service written in WCF Rest
My Service
[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;
}
And my Client request is
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"));