Thanks Scott for your valuable suggestions.

On Wed, Jan 9, 2019 at 3:10 AM <sc...@ser.vi> wrote:

>
>
> On Tuesday, January 8, 2019 at 4:35:47 PM UTC-5, Scott Logsdon wrote:
>>
>> Suresh,
>>
>> The issue is not on the client side but rather on the server side.  The
>> server cannot accept the request because it is cross domain and has not
>> been allowed.   When you do an HTTP request outside of your local domain,
>> CORS will perform what is called a "pre-flight check" to see if the request
>> is allowed.  If you look at your console you will notice 2 identical calls
>> back to back.  The first being the pre-flight check and if allowed the
>> second will have the actual API response.  When this happened to me, I also
>> went crazy trying to figure it out, thinking something was wrong with my
>> Angular code when in fact it had nothing to do with it,  That being said, I
>> found the easiest way around the issue was to add an .htaccess file to the
>> API server main root.  Of course you need to have access to your API.  I
>> use SlimPHP for my backend API.  Some servers will allow you to use the
>> wildcard * for Access-Control-Allow-Origin but it gave me issues with
>> Heroku which is the platform we use.   I added this to .htaccess.  Change
>> domain1, domain2, domain3 to your allowed domains or remove/add more.
>>  Again you might be good with just the wildcard on that line:  Header
>> set Access-Control-Allow-Origin *   If that is the case you can also
>> remove the SetEnv and Header merge lines
>> :
>>
>>> <IfModule mod_headers.c>
>>>     SetEnvIf Origin
>>> "http(s)?://(.+\.)?(domain1\.com|domain2\.net|domain3\.com|localhost)(:\d{1,5})?$"
>>> CORS=$0
>>>     Header set Access-Control-Allow-Origin "%{CORS}e" env=CORS
>>>     Header merge  Vary "Origin"
>>>     Header set Access-Control-Allow-Headers "Origin, X-Requested-With,
>>> Content-Type, Accept, Authorization,
>>> Access-Control-Request-Method, Client-Security-Token, Accept-Encoding"
>>
>>     Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE,
>>> OPTIONS"
>>>     Header set Access-Control-Allow-Credentials true
>>> </IfModule>
>>
>>
>>
>> Hope this helps.
>>
>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Angular and AngularJS discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+unsubscr...@googlegroups.com.
> To post to this group, send email to angular@googlegroups.com.
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to