lizyjeywin lizyjeywin - 1 month ago 12
Javascript Question

Can we have an Ajax Call inside Marketo Load script

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

    });
    });




Answer

Yes I am able to call an ajax from Marketo Script. Need to add the jQuery lib too for this. The below is the complete working snippet.

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

      });
});
Comments