Salesforce - success handler for calling $ .ajax

I have a form that I submit to Salesforce with a standard form view. By default, you can tell Salesforce to redirect you to the specified URL after the POST completes.

I no longer want to be redirected, since I have other actions on the form page. No problem, my page already uses jQuery, so I can use the convenient $ .ajax utility, for example:

$('#wrapper').on('click', '#formsubmit', function(e) {
    e.preventDefault();

    var formData = $('#subForm').serialize();
    $.ajax({
      type: "POST",
      url: "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8",
      data: formData,
      success: function() {
        console.log('success!'); // or not!
      },
      error:function (xhr, ajaxOptions, thrownError){
                    console.log(xhr.status); // 0
                    console.log(thrownError); // empty
                }
    });
});

In my lost mind, I realized that Salesforce would return my good call forwarding, which would be considered a β€œsuccess,” which I could simply discard / ignore. Not true!

  • I see a 200 OK result (which usually means "success"), but the success callback does not work.
  • The listing is added to the Salesforce database.
  • ; .
  • ( 200 OK), , , - " "? ( 0, thrownError ?).

POST, ? , , , POST, . - .

, , JSONP, , ( , ).

+3
2

:

1) , API Salesforce, , .

2) ( ) 200 OK, - .

3) POST JSONP. JSONP; AJAX, HTTP GET-, script. , JSONP , HTTP- 200 OK.

POST AJAX. - API- Salesforce. , .

+3
var formData = $('#subForm').serialize();
   var response = $.ajax({
      type: "POST",
      url: "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8",
      data: formData,
      success: function() {
        console.log('success!'); // or not!
      },
      error:function (xhr, ajaxOptions, thrownError){
                    console.log(xhr.status); // 0
                    console.log(thrownError); // empty
                }
    }).responseText;

var ajax-

0

All Articles