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

user4582995 picture user4582995 · Dec 31, 2015 · Viewed 8.9k times · Source

I am trying to run my phonegap app on ripple emulator and calling method from webservice.asmx using ajax method in jquery, but got cors error:

XMLHttpRequest cannot load https:\rippleapi.herokuapp.com\xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//www.my-domain.com/WebService.asmx/selectData. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:\localhost:4400' is therefore not allowed access. The response had HTTP status code 503.

  1. Have given cors on server side (web.config):

<system.webServer> <defaultDocument> <files> <clear /> <add value="index.aspx" /> <add value="WebService.asmx"/> </files> </defaultDocument> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*"/> <add name="Access-Control-Allow-Headers" value="Content-Type"/> </customHeaders> </httpProtocol> </system.webServer> <system.web> <webServices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webServices> <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/> </system.web> <system.serviceModel>

  1. My AJAX method :

    $.ajax({
    type:"POST",
    crossDomain : true,
    url: "http://www.my-domain.com/WebService.asmx/selectData",
    data: JSON.stringify(campaignData),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg)
    {
    var response=msg.d;
    var resultLoop=$.parseJSON(response);
    console.log(response)
    },
    error: function(xhr, ajaxOptions, thrownError)
    {
    $.mobile.loading('hide');
    alert("status :"+xhr.status +" thrownError :"+ thrownError +" ajaxOption : "+ ajaxOptions);
    }
    });

Not able to resolved this, don't know where I have done something wrong or missing something where I have to change in code so that it communicate with server and get data.

Answer

user4582995 picture user4582995 · Feb 2, 2016

was running phonegap app on ripple emulator, changed cross domain proxy setting to disabled and it worked.