1

I'm trying to echo something via Ajax but I'm not getting any output. So I would add a pair of error handling to see what is working wrong.

How can I add simple error handling code to see where the error is?

page.html

<body>
    <input id="name" type="text" />
    <input id="button" type="button" value="Load" />
    <div id="feedback"></div>

    <script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript" src="ajax.js"></script>
</body>

page.php

<?php
  if (isset($_GE['name'])) {
     echo $name = $_GET['name'];
  }
?>

ajax.js

$('#button').click(function () {
    var name = $('#name').val();
    $.ajax({
        url: 'page.php',
        data: {
            name: name
        },
        success: function (data) {
            $('#feedback').html(data);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log(textStatus, errorThrown);
        }
    });
});
Spokey
  • 10,974
  • 2
  • 28
  • 44
Aex Sun
  • 337
  • 5
  • 13

1 Answers1

0

Are you running this from your local drive? If so, your browser will block the request due to null origin policy. As far as debugging goes, the best option you have is to go to your developer tools' network tab and it will show it going through.

Edit: Nevermind the first part I noticed you are using a php server.

Andrei Nemes
  • 3,062
  • 1
  • 16
  • 22