EDIT: So, after a few days fighting this, I will post my final solution, which may help others trying to contact Pardot using JSONP. This is a problem with three parts:
- Send a JSONP request to the Pardot form handler
- Redirect the successful / error Pardot form handler to your own server.
- Return JSONP from your server.
Send JSONP request for Pardot From Handler
To submit form data to a form handler, you need the URI to encode field names and values.
(An example of using jQuery. '? Callback =' is added by ajax () when specifying dataType: 'jsonp'):
var data = { 'field1' = 'value1', 'field' = 'value2' }; var uriEncodedParams = $.param(data); var targetUrl = <Pardot Form Handler URL> + '?' + uriEncodedParams; $.ajax({ action = targetUrl, dataType: 'jsonp', jsonpCallback: 'callback' }); window.callback = function (data) {...}
Pardot Redirection From Success / Error Handler to Your Own Server
See @nickjag answer:
Set the location of the location of successful tasks and the location of the error to the endpoints on your server.
Since pardot will not redirect any of the GET parameters you passed, you will have to use some default values, that is, the name of the callback function (therefore, specify jsonpCallback and not succeed in my request).
Return JSONP from your server
I am having problems with console errors ( Uncaught SyntaxError: Unexpected token : when using: return "{ 'result' : 'success' }" because it is a JSON object and JSONP is expecting a file with JavaScript. Thus, the format for the return should be: return "callback({ 'result' : 'success' })"
And how again Pardot does not redirect the GET parameters, the generated callback function name from JQuery did not propagate, and I could not return the correct JavaScript code. By default, the callback function name is used if none were provided.
Guide for returning JSONP from the .NET MVC backend
source share