How to call .NET web service from ajax call? I am facing same origin policy error. How can I resolve that?
Asked
Active
Viewed 36 times
1
-
What service? Web API, WCF, ASMX? – Oscar Sep 29 '16 at 10:03
-
It is asmx web service @Shuping. I have tried header("Access-Control-Allow-Origin: *"); in php but the issue didn't resolve. – Mohit Gaur Oct 03 '16 at 05:10
-
The COR header should be put in the target service which is your ASMX service instead of in PHP – Shuping Oct 04 '16 at 05:19
-
@Shuping No, COR headers are sent by the server, and must be issued from server side using something like PHP http://enable-cors.org/server_php.html – Oscar Oct 05 '16 at 19:54
-
@Oscar "sent by the server" is exactly what i am saying. Check the question: the server side (of the Web Service) is ASMX which is .NET, that's why I am saying the ASMX service (which is for sure the server side of the API) should attach the COR headers. And from Gaur's comment, the PHP code if for building the AJAX pages, is actually "client side" to the ASMX. – Shuping Oct 06 '16 at 12:37
1 Answers
-1
Your web service should allow you to request on It.
For example in php
<?php
header("Access-Control-Allow-Origin: *");
Where "*" could be replaced by your server location
In dot net, it could be something like (I don't know .NET)
[EnableCors(origins: "http://mywebclient.azurewebsites.net", headers: "*", methods: "*")]

A.Massard
- 44
- 7