So, we've been experimenting with POSTing our form submission data directly to `/index.php/leadCapture/save2. We are interested in doing this because we have our own custom form journey, and we basically followed along with the same logic that's in Marketo's forms2 github. We are using AJAX to POST to Marketo, ie:
this.ajax = $.ajax({
method: "POST",
context: this,
url: "https://marketostuff.com/index.php/leadCapture/save2", //this is a dummy url
contentType: 'application/json',
dataType: 'jsonp',
timeout: 7000,
data: this.payloadState,
beforeSend: this.ajaxBeforeSendFn,
})
.done( this.ajaxSuccessFn )
.fail( this.ajaxErrorFn )
.always( this.ajaxAlwaysFn );
So out of like 100 or so tests, we've noticed that 2-3 have resulted in a timeout error. Not getting any response headers back. Everything else is working like a champ! The timeout response looks like:
"response": {
"readyState": 0,
"status": 0,
"statusText": "timeout"
}
So, i'm wondering what might be going on if this function works 97-98% of time time, what could be causing the response to timeout? We do have a timeout limit in our AJAX call (7 seconds).... which I imagine is actually timing out. Not sure if things are getting stuck in Preflight... but at the very least we know that we aren't getting any response, so it doesn't seem like a preflight rejection outright.
Does anyone have thoughts? Thanks so much for your help and time,
Gabriel
You can't POST JSONP. It's always going to be a GET so that field is very misleading.
Not sure what's giving you the impression that Forms 2.0 does what you're attempting here. A standard Forms 2.0 post is an application/x-www-form-urlencoded POST from a same-origin IFRAME.
The payload is sent to LeadCapture as key=value params in the POST URL, so that's OK.
So the question is, if this works 99% of the time, what are the possible reason(s) that could cause the server to timeout the remaining 1%? I'm assuming that a timeout means that there's no response at all from the server. While I'm curious, I totally understand that there may be other several different factors/implications. I'm sure there's probably a preflight check before the data is actually sent because these requests are all cross-domain, and maybe something is not responding there. Or, maybe there's a limit to the number is requests that i don't know about.
Thanks for your thoughts!
Best,
Gabriel
The payload is sent to LeadCapture as key=value params in the POST URL, so that's OK.
No POST is happening. JSONP is not a POST.
I'm sure there's probably a preflight check before the data is actually sent because these requests are all cross-domain
JSONP is not preflghted. It's an injected script that is GETted.
I wouldn't advise trying anything that you're doing — none of it is remotely supported and there's already an easy and supported way to get the same result (e.g. use the Forms 2.0 API and a hidden form).
POST-ing directly to /save2 is unsupported and is not guaranteed to work in the future. I would advise not going this route.