我的要求
请建议实施此解决方案。
我尝试了什么
为此,我试图在点击Marketo提交时使用ajax,但它不起作用, 它会非常麻烦地停止,甚至不会返回到Marketo中指定的ReturnURL。我试过的代码:
<script src="//xxxxx.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_1"></form>
<script>
MktoForms2.loadForm("//aqq-abc.marketo.com", "xxx-XXX-xxx", id1, function(form) {
form.onSubmit(function(e) {e.preventDefault();
var vals = form.vals();
$.ajax({
type: "POST",
url: "http://localhost:3422/wordpress/plugin/calculationFILE.php",
data: {Value1:val["Email"],Value2: vals["Phone"]},
success: function( data ) { alert(data); },
error: function( err ) {alert("Some thing went wrong! Please try again with your values.");}
}); //ajax call end
alert("OK after ajax"); //========>THIS IS NOT CALLED-but if ajax statement removed this alert fires.
});//OnSubmit end
});//loadForm End
修改
我已经在上面的代码中包含了e.preventDefault()。我仍然无法看到执行ajax调用。 我是否需要包含jQuery才能使其工作? 我在这里失踪的是什么 您对解决方案的建议对前进有很大帮助。
答案 0 :(得分:0)
我必须包含jQuery lib来进行ajax调用。之后它识别出ajax调用。完整的工作片段是
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//xxxxx.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_1"></form>
<script>
MktoForms2.loadForm("//aqq-abc.marketo.com", "xxx-XXX-xxx", id1, function(form) {
form.onSubmit(function() {
var vals = form.vals();
$.ajax({
type: "POST",
url: "http://localhost:3422/wordpress/wp-content/plugins/calM/new_generate.php",
data: {Value1:vals.Email,Value2: vals.Phone},
success: function( data ) {
alert(data);
},
error: function( err ) {alert("Some thing went wrong! Please try again with your values.");}
});
});
});