使用JavaScript URL模拟JSONP响应 [英] Simulate a JSONP response with JavaScript URLs

查看:103
本文介绍了使用JavaScript URL模拟JSONP响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WP网站上使用重力形式.我的表单通过ajax使用Pardot

I'm using Gravity Forms on a WP site. My forms POST via ajax to Pardot using Pardot form handlers. I am running into an issue where Pardot processes the form 6x, with no other errors. Research indicates that this is because Pardot does not support CORS or JSONP, and thus gets stuck in a loop when using ajax to submit. It's processing the submission but never "finishing" when the form handler's Success URL is set as referring URL. It tries 6x before giving up, processing the submitted data and sending new prospect notification emails each time.

Pardot 帮助文档建议以下解决方案:

Pardot help docs suggest the following solution:

通过将表单处理程序的成功和错误URL设置为分别执行成功和错误回调的JavaScript URL,可以模拟JSONP响应.

It is possible to simulate a JSONP response by setting the Success and Error URLs for the form handler to be JavaScript URLs that execute Success and Error callbacks, respectively.

我不确定这意味着什么或如何实现.我已经做了一些stackoverflowing和谷歌搜索,但我似乎无法全神贯注于如何做到这一点.有人可以帮助您澄清这个概念或为我指明正确的方向吗?

I'm not totally sure what this means or how to approach it. I've done some stackoverflowing and googling, but I can't seem to wrap my head around how to do it. Can someone help clarify this concept or point me in the right direction?

谢谢!

推荐答案

Pardot的建议是在您自己的服务器上创建2个静态URL,这些URL返回简单的JSON响应.

What Pardot is suggesting is to create 2 static URLs on your own server that return a simple JSON response.

例如:

  1. mysite.com/pardot-success

返回:{"result":"success"}

  1. mysite.com/pardot-error

返回:{"result":"error"}

然后,您将使用这两个URL作为Pardot表单处理程序设置的成功和错误重定向URL.

You'll then use those two URLs as your success and error redirect URLs for your Pardot form handler settings.

然后可以使用JSONP向您的Pardot表单处理程序发出AJAX请求,该请求将包装并返回其中一个URL的JSON响应(取决于结果).

An AJAX request can then be made to your Pardot form handler using JSONP, which will wrap and return the JSON response from one of those URLs (depending on the result).

您的AJAX响应数据将包含您的JSON结果(成功或错误).

Your AJAX response data would include your JSON result (success or error).

这篇关于使用JavaScript URL模拟JSONP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆