0

Where is the error, console is spitting back ID is not defined, I want the "url: id" to select a button depending on its id to return a result and display it on a div on the index

<script type="text/javascript">
  jQuery(document).ready(function ($) {
    $('button').click(function() {
        $(this).attr("id");
        switch(id) {
            case 1:
                id = 'Reportes/Empresas.php'
                break;
            case 2:
                id = 'Reportes/Departamento.php'
                break;
            case 3:
                id = 'Reportes/Empleados.php'
                break;
        }
      $.ajax({
        type: 'GET',
        url: id,
        data: '',
        datatype: 'html',
        cache: 'false',
        success: function(response) {
          $('div.results').append(response);
          alert('Load was performed.');
        },
        error: function(){
          alert('Nope');
        }
      });

      alert('Fail');
    }); // End onclick
  });
</script>

My coworker says there are three errors, but cant help right now.

1
  • Daniel, if the answer below is useful, you can click its checkmark to accept it. Commented Jul 15, 2016 at 16:19

2 Answers 2

3

You never defined id in the first place:

        $(this).attr("id");
            switch(id){
                  ^^^^--undefined

Maybe you meant

id = $(this).attr('id');
^^^^^

instead.

Sign up to request clarification or add additional context in comments.

Comments

0

be sure from button selector and attribute is true. Usage have to be like this.

<button type="button" id="Reportes/Empresas.php" class="display_db_table">Show Table</button>

$('.display_db_table').click(function() {

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.