0

Ajax will not submit no matter what.
I've been trying for hours...

script:

<script>
  $(document).ready(
    $("#submit").click(function(e) {
      e.preventDefault();
      $.ajax({
        url: "https://maps.googleapis.com/maps/api/geocode/json?address=birmingham&key=AIzaSyCczrRP8E0BYmt9uGie0J3SgCn9ahdOhxc",
        type: "GET", 
        dataType: "html",
        success: function (data) {
          alert(data);
        }
      });
    });
  });
</script>
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
  • 2
    What does the console say? That ready is missing a open curly brace and it's anonymous function. Here read this next time https://learn.jquery.com/using-jquery-core/document-ready/ – Darkrum May 31 '17 at 02:07
  • 2
    Right off hand without being able to see your console, I'd say you have a _Syntax Error_... – War10ck May 31 '17 at 02:48

2 Answers2

0

Try this:

$(document).ready(function({
    $("#submit").on('click', function(e) {
        e.preventDefault();
        $.ajax({
            url: "https://maps.googleapis.com/maps/api/geocode/json?address=birmingham&key=AIzaSyCczrRP8E0BYmt9uGie0J3SgCn9ahdOhxc",
            type: "GET", 
            dataType: "html",
            success: function (data) {
                alert(data);
            }
        });
    });
});

I also changed the event method, but you should choose the one corresponding your jQuery version!!

P.S re-check the ({})

Taf Hyseni
  • 41
  • 3
  • *"I also changed the event method"* - Why change `.click()` to `.on('click')`? (For the minuscule performance improvement that has nothing to do with the OP's problem? If so, say so.) – nnnnnn May 31 '17 at 03:18
  • There are plenty of reasons why I prefer .on rather than .click! And as for that I recommended him to use .on! Pattern and namespaces are just few of them. For more on this: https://stackoverflow.com/questions/9122078/difference-between-onclick-vs-click – Taf Hyseni May 31 '17 at 09:41
0

You've not written document ready properly. Please check below code :

<script>
    $(document).ready(function() {
        $("#submit").click(function(e) {
            e.preventDefault();
            $.ajax({
                url: "https://maps.googleapis.com/maps/api/geocode/json?address=birmingham&key=AIzaSyCczrRP8E0BYmt9uGie0J3SgCn9ahdOhxc",
                type: "GET", 
                dataType: "html",
                success: function (data) {
                    alert(data);
                }
            });
        });
    });
</script>

I hope this resolves your issue.

PS:
FYI check the alternative ways to write document ready : Documentation

Happy Coding

Touheed Khan
  • 2,149
  • 16
  • 26