function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Radhika Pawar 12Radhika Pawar 12 

Access to XMLHttpRequest at 'https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8' from origin 'https://author-uat.aem.avi.com' has been blocked by CORS policy:

Hi All,

I am receving the velow error when record submitted via web form. this functionality developed using web-lead .
Error:
Access to XMLHttpRequest at 'https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8' from origin 
'https://author-uat.aem.avi.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. 

Web-Lead Form:
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: Please add the following <FORM> element to your page.             -->
<!--  ----------------------------------------------------------------------  -->

<form action="https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="1198D1x111118glX">
<input type=hidden name="retURL" value="https://google.com">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="pawar.radhika@avivainvestors.com">                               -->
<!--  ----------------------------------------------------------------------  -->

<label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" Required/><br>

<label for="email">Email</label><!--<input  id="email" maxlength="80" name="email" size="20" type="text" Required/><br>-->
<input id="email" name="email" type="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" Required/><br>
<input type="submit" name="submit">

</form>

 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Radhika,

According to Salesforce Knowledge Article:

Update Web-to-Case and Web-to-Lead endpoint URLs to improve performance

1. What is the change and impact?
To improve the performance of the Web-to-Case (W2C) and Web-to-Lead (W2L) functionality, the endpoint that receives the W2C/W2L form submission data from company websites to create leads/cases in Salesforce will be replaced with a new endpoint on April 20, 2018. Websites using the W2C/W2L forms will cease to create new cases and/or leads within customers’ Salesforce orgs if the websites are not updated with the new endpoint URL by April 20, 2018. 

2. What action do I need to take? 
Customers using either or both of these functionalities will need to update the W2C/W2L HTML code in their websites by April 20, 2018. As the new endpoint URL is already available, customers are strongly encouraged to complete these updates as soon as possible to take advantage of the improved functionality performance.

To make the HTML code update on the websites, admins should provide the following information to their company webmaster:

1. For websites that contain the Web-to-Case and/or Web-to-Lead forms, do a global search across the website HTML code for either of these code snippets:
“https://www.salesforce.com/servlet/servlet.WebToLead”
“https://www.salesforce.com/servlet/servlet.WebToCase”
 
2. Replace the “www” with “webto” so that the “form action” URLs in the Web-to-Case and Web-to-Lead HTML code display as such:
“https://webto.salesforce.com/servlet/servlet.WebToLead”
“https://webto.salesforce.com/servlet/servlet.WebToCase”
 
3. How should I test this change?
Upon your developer review of the HTML code change on your website, test the creation of new cases and/or leads in your production org prior to pushing the updated HTML code to your production website. 

Example testing steps may include the following:
1. Modify your current Web-to-Case and/or Web-to-Lead form with the new endpoint URL update. To see where the endpoint URL is located, see the Web-to-Lead Form HTML Code Generation and/or Web-to-Case Form HTML Code Generation screenshots below.

2. Copy the updated HTML form markup and test the form in a test editor such as JSFiddle. Enter new case and/or lead information in the form. See the JSFiddle Test Editor screenshot below.

3. Confirm that the new leads and/or cases are captured in your Salesforce org. See the Example lead capture confirmation screenshot below.
 
Web-to-Lead Form HTML Code Generation
The Web-to-Lead HTML code generator can be found by navigating to Setup | Build | Customize | Leads | Web-to-Lead | “Create Web-to-Lead”, which takes you through the setup of entering your Return URL, which then allows you to generate the Web-to-Lead form code.
The form action URL  contains the Salesforce endpoint that receives the Web-to-Lead form submission data to Salesforce. This is the endpoint URL which needs to be updated.
 
Web-to-Case Form HTML Code Generation
The Web-to-Case HTML code generator can be found by navigating to Setup | Build | Customize | Self-Service | Web-to-Case HTML Generator, which takes you through the setup of entering your Return URL, which then allows you to generate the Web-to-Case form code.
The form action URL contains the Salesforce endpoint that receives the Web-to-Case form submission data to Salesforce. This is the endpoint URL which needs to be updated.

Note: This apply for Production URLs only and No changes are needed for Sandbox.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Taoufiq Benallah 1Taoufiq Benallah 1
Khan Anas  : He is looking for a solution tpo AJAX form subbmission, and your answer is not what he is looking for! Thanks