0

I'm running into an error which reads as follow in the console of my Google Chrome browser:

Uncaught SyntaxError: Unexpected end of input

Below is my code:

/*=====  Login Alert  ======*/

function loginAlert() {
    swal({   
        title: "Login Required",   
        type: 'error',
        text: "Please <a href='/login'>login</a> first to submit your ticket.",   
        html: true,
    });
}

What am I doing wrong and how can I resolve it?

nyedidikeke
  • 5,016
  • 7
  • 33
  • 49
Melon
  • 11
  • 5
  • 1
    You have a `,` at the end there, shouldn't be there. Also, this looks like javascript to me? So, your problem might be somewhere else, as your error is indeed within `php`. – Nytrix Apr 23 '17 at 00:11
  • 1
    @Nytrix Re: the comma, read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas – ceejayoz Apr 23 '17 at 00:45

1 Answers1

0

This is what you should be doing.

Take a look at the snippet below:

$(document).ready(function() {
  $("#loginBtn").on("click", function() {
    swal({
      title: 'Login Required',
      type: 'error',
      text: 'Please <a href="login">login</a> first to submit your ticket.',
      html: true,
    });
  });
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<button id="loginBtn">Login Test</button>

The Uncaught SyntaxError: Unexpected end of input error you have indicates that you have an improperly terminated function or statement.

Take a look at this for more details and resolution; you should consider going through your code as the actual error must be somewhere else.

Community
  • 1
  • 1
nyedidikeke
  • 5,016
  • 7
  • 33
  • 49