Hi Team,
We have an third-party API when hit in browser address bar returns JSON response(session token) and creates few browser cookies which are used subsequently. We are trying to invoke this API via jQuery ajax call with dataType=jsonp, able to access JSON response but browser cookies are not created. As a result of this, subsequent functionality which is dependent on browser cookies is not working as expected.
Is there any way to solve this issue?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi Srikanth,
If your third party API is hosted in a different domain than your AEM then those cookies might not set onto your browser when you make an ajax from aem. Please look into the below articles which might give you more insight. Also chrome and safari are restricting third party cookies.
https://stackoverflow.com/questions/69448732/how-to-set-correct-cookies-in-express
Consider writing a SlingServlet which will make the third party API call. Call this SlingServlet from your ajax. This might resolve your issue and also avoid browser CORS issue.
Thanks
Hi @srikanthpogula ,
Try this below
$.ajax({ url: a_cross_domain_url, xhrFields: { withCredentials: true } });
Ref: https://stackoverflow.com/questions/2870371/why-is-jquerys-ajax-method-not-sending-my-session-cookie
Regards,
Santosh
Hi @santhosh_kumark , the session toke API call itself creates browser cookies, its currently happening when API is hit in browser address bar. I am not trying to send cookies to API via ajax call. I am looking for way to invoke the API and get it to work in a similar way from AEM clientlibs, how it works when hit in browser address bar.
Regards,
Srikanth
Hi Srikanth,
If your third party API is hosted in a different domain than your AEM then those cookies might not set onto your browser when you make an ajax from aem. Please look into the below articles which might give you more insight. Also chrome and safari are restricting third party cookies.
https://stackoverflow.com/questions/69448732/how-to-set-correct-cookies-in-express
Consider writing a SlingServlet which will make the third party API call. Call this SlingServlet from your ajax. This might resolve your issue and also avoid browser CORS issue.
Thanks