Can we have an Ajax Call inside Marketo Load script

时间:2016-10-20 12:41:31

标签: javascript jquery marketo

Is it possible to call an Ajax from the Marketo script? Like the below given code.

I would need an ajax call as

  1. I want to pass the Marketo Form values to a php file
  2. then use the values to do some calculation
  3. then to display the results on the page

    <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:val[0],Value2: vals[1]},
            success: function( data ) {
                        alert(data);
    
            },
            error:  function( err ) {alert("Some thing went wrong! Please try again with your values.");}
            });
    
          });
    });
    

2 个答案:

答案 0 :(得分:0)

这应该在原则上正常工作。取决于你尝试做什么onValidate可能是一个更好的回调事件。

答案 1 :(得分:0)

是的,我可以从Marketo Script调用ajax。需要为此添加jQuery lib。以下是完整的工作片段。

<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.");}
        });

      });
});
相关问题