leadCapture/save in Ajax get FAIL status | Community
Skip to main content
New Participant
December 25, 2020
Solved

leadCapture/save in Ajax get FAIL status

  • December 25, 2020
  • 1 reply
  • 6754 views

Hi,

I need to send lead from sever to sever, here is the code when the form is submitted:

let data= { 'munchkinId': 'xxx-xxx-xxx', 'formid': xxx, 'Email': 'xxxx@xxx.com' } $.ajax({ type: 'POST', url: '//xxx.oursite.com/index.php/leadCapture/save', data: data, success: function (data) { console.log('run callback here'); }, error: function (xhr, error) { console.log(xhr, error); } });
by doing this, I can send this lead to Marketo but I get failed status. since I need a callback when lead is sent, does anyone know how to fix this?
 
Best answer by SanfordWhiteman

The forms endpoint isn't to be used directly. Use the Forms API to submit a background form as noted here: https://developers.marketo.com/blog/make-a-marketo-form-submission-in-the-background-3/

1 reply

SanfordWhiteman
New Participant
December 25, 2020

An Ajax POST isn't "server to server." Please explain in detail what you're sending and where the form lives.

JustinWenAuthor
New Participant
December 25, 2020
Sorry for the confusion. it is not server to sever. Basically, when the user submits a form I will send a lead to markto by using this code:
HTML:
<form> <input type="button" class="js-lead-capture" value="Submit"> </form>
 
JS:
$('.js-lead-capture').click(function (e) { e.preventDefault(); const data = { 'munchkinId': 'xxx-xxx-xxx', 'LeadSource': $.cookie('XYZutm_source'), 'Phone': '888-888-8888', 'Person Source': 'test', } $.ajax({ type: 'POST', url: '//mysite.com/index.php/leadCapture/save', data: data, success: function (data) { //do something else here: console.log('data sent'); }, error: function (xhr, error) { console.log(xhr, error); } }); })
 
when running this test, I can see the lead is added into markto but return a 'failed' status response (as I sent that screenshot) so that my success function does not get through.
 
thanks,
 
JustinWenAuthor
New Participant
December 25, 2020
const data = { 'munchkinId': 'xxx-xxx-xxx', 'formid':'xxxx', // (formid is included) 'LeadSource': $.cookie('XYZutm_source'), 'Phone': '888-888-8888', 'Person Source': 'test', }