Having problem when using POST using JSON in ASP.NET. Kindly check my code when I used POST. Is there's something wrong when javascript code?
Exact error :
Failed to load resource: the server responded with a status of 405 (Method Not Allowed) localhost:99/Service1.svc/api/updtelogin.json XMLHttpRequest cannot load localhost:99/Service1.svc/api/updtelogin.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:1110' is therefore not allowed access. The response had HTTP status code 405.
IService
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "api/updtelogin.json")]
UpdateUser updteUser(RequestData rData);
RequestData
[DataContract(Namespace = "")]
public class RequestData
{
[DataMember]
public string details { get; set; }
}
Service.svc
private UpdateUser updateuser(RequestData rData)
{
return updteUser(rData);
}
public UpdateUser updteUser(RequestData rData)
{
var data = rData.details.Split('|');
}
And this is my javascript from ASP.NET
<script type="text/javascript">
$("#btnChange").live("click", function () {
var test = {};
test.uname = "admin";
$.ajax({
type: 'POST',
url: 'http://localhost:99/Service1.svc/api/updtelogin.json',
data: "{rData:" + JSON.stringify(test) + "}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (r) {
alert(r.d.uname);
}
});
});
</script>