0

can someone explain this bit of code?

<script type="text/javascript"><!--

    $('#button-confirm').bind('click', function() {
        $.ajax({ 
            type: 'get',
            url: 'index.php?route=hybrid_directory/confirm',
                success: function() {
                    location = '<?php echo $continue; ?>';
            }
        });
    });

    function formSubmit()
    {
        document.getElementById("freecontactform").submit();
    }

//--></script>

button-confirm, when clicks submits the information from a php contact form. how is url and function - location used?

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
Alexand657
  • 115
  • 1
  • 3
  • 12
  • @JonathanWood, those are html comments. Inside script blocks they do not interfere with the script, but they protect the code from being shown from older browsers who did not support the script tag.. read http://stackoverflow.com/questions/808816/are-html-comments-inside-script-tags-a-best-practice (*it should not be used nowadays though..*) – Gabriele Petrioli Dec 04 '12 at 01:10
  • its on a smmarty template page (.tpl) – Alexand657 Dec 04 '12 at 01:11
  • @NiklasB. and Gaby: Ah, right you are. – Jonathan Wood Dec 04 '12 at 01:12

1 Answers1

2

This is an ajax call, triggered when an element with an id of "button-confirm" is clicked.

When the ajax call is complete, the url relocates to whatever the PHP script loading this page defined as $continue

Here's the docs to the jquery ajax method: http://api.jquery.com/jQuery.ajax/

Kai Qing
  • 18,793
  • 5
  • 39
  • 57
  • ok and if the button is also assigned to submit freecontactform (which has a thank you page set to "www.google.com") , will the user be directed to the thank you page, or the url in the ajax code? – Alexand657 Dec 04 '12 at 01:15
  • well, an element can't be assigned 2 id's. It will likely take the first instance, depending on how the html is written. But if the form is posted it will leave the page. The listener doesn't prevent defaults, so I would bet the natural form submit would happen first. Of course, the logical thing to do is to simply try it out and see what happens. – Kai Qing Dec 04 '12 at 01:18
  • That's where this situation comes into play: http://stackoverflow.com/questions/13694682/ajax-submit-script-basic-submit . Feel free to check it out – Alexand657 Dec 04 '12 at 01:25