No 'Access-Control-Allow-Origin' header is present on the requested resource

Posted by Vuyiswamb under ASP.NET AJAX on 1/30/2014 | Points: 10 | Views : 49119 | Status : [Member] [MVP] [Administrator] | Replies : 1
Good Day

i have a web api that i want to call on the client side and return its contents, so it s a post and i return some string. Now i have a form that will have the data to be posted as depicted below

    <form name="registrationForm"    method="post">


and there are other controls within the form and i have a button that triggers the post as depicted below


<input title="Register" onclick="ProcessRegistration();" style="width: 100px; height: 100px; align-self: center" type="submit" name="submit_fourth" id="submit1" value="register" />


onCick i call a function from the client side, the definition of the function is


     function ProcessRegistration()
{

$.getJSON("http://www.mydomain.maindomain.com/api/Registration/Create", function (data) {

alert(data);
});


}



now when i click the button to fire the service i get the following error in the console


XMLHttpRequest cannot load http://www.mydomain.maindomain.com/api/Registration/Create. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:46506' is therefore not allowed access. 



Does anyone know how to solve this ?

Thanks

Thank you for posting at Dotnetfunda
[Administrator]



Responses

Posted by: kgovindarao523-21772 on: 1/31/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Try like this.

$.ajax({
type: "POST",
url: "http://www.mydomain.maindomain.com/api/Registration/Create",
contentType: "application/json; charset=utf-8",
data: oEmployee,// if Data should complex type,then pass object here, else null
dataType: "json",
success: function (obj)
{
alert(obj);// Do manipulations here
},
error: function (result)
{
alert("POST Method, Error in binding....... ");
}
});


Thank you,
Govind

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response