I am trying to submit my webtolead form, somethinf that is so simple and basic jQuery, But I am getting CORS origin error :


    // https://www.domainName.my.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8

    function postFormAjax(formData) {
            method: "POST",
            type: "POST",
            url: "https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8",
            headers: {
                'Access-Control-Allow-Origin': '*'
            data: formData,
            processData: false,
            contentType: false,
            crossOrigin: true,
            crossDomain: true,
            error: function (jqXHR, textStatus, errorMessage) {
                if (textStatus == "error") {

            success: function (data, textStatus, xhr) {

    postFormAjax({ first_name: "test", email: "test@gmail.com" })


This is the error :

Access to XMLHttpRequest at 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8' from origin 'null' 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.

Also I feel like there is something important about this field :

enter image description here

I don't find many clear guides on how to submit webtolead forms via XMLHTTPSREQUEST !!

Any help or indication here would be much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.