Hi guys! Hope you're having a great day. So i am c...
# suitecommerce
b
Hi guys! Hope you're having a great day. So i am calling a suitelet using ajax in order to send an input file by appending it to a formData object. In 2019 i just added this line to the suitelet and the file was saving successfully.
context.response.addHeader({ name: 'Access-Control-Allow-Origin', value: '*' });
We migrated to 2022 and now that is not working at all. Any ideas why or if I am missing something else? Thank you!!!
f
there are things that have been deprecated since 2019
I think that now you are required to set the encoding, using standard suitescript 2 http response object
b
Hi!! Thank you for your time!
I am adding that header inside the onRequest(params) function.
f
something like
context.response.addHeader({name: 'Access-Control-Allow-Origin', value: 'application/json; charset=utf-8',});
ah ok
b
It is a suitelet called using ajax in a website form.
It is working fine in our current implementation 2019. But in our sandbox site (2022.2) it is not working but it is the same call and same suitelet code.
Si instead of having the * in the value property i need to change it to application/json…?
f
that was just an example of an issue I recall the team worked on
b
Ahh i see 🙂
So how did you fix the cors issue?
I added the line
context.response.addHeader({ name: 'Access-Control-Allow-Origin', value: '*' });
inside the onRequest(params) function but on the console i am seeing the error: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I am calling the suitelet from my sandbox site.
Shouldn't i be able to access the suitelet with no issues? 😕
m
I think you can just replace the domain with your webstore domain and the suitelet will still work. This will bring CORS into alignment. Or just make the URL relative without the domain when calling it from the form. But your suitelet must be externally available in order to call it.
🙏 1
b
Thank you so much for your input! Will try that in the morning. 🙏🏻