0

The below code is intended to return json object from arraylist but it is not showing alert. there is no js error...

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="json.js" />
<script type="text/javascript" src="json2.js" />
<script type="text/javascript">
var my_info= {};
my_info["john"]="1a";
my_info["joseph"]="2b";
my_info["helen"]="3c";

var val = JSON.stringify(my_info);

alert(val);
</script>
</head>
<body>

</body>
</html>
2
  • remove the links having json.js and json2.js. The alert doesn't show if they are not available. Commented Aug 22, 2013 at 4:01
  • @sza That's false. A 404 error will not block the other js code running. The answer is that the script tags do NOT allow self closing. Commented Aug 22, 2013 at 4:11

1 Answer 1

1

Script tags don't allow self-closing (<script ... />). You have to use <script src="..."></script> instead.

See for more information this question.

Your code becomes:

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="json.js"></script> <!-- Here -->
        <script type="text/javascript" src="json2.js"></script> <!-- And here -->
        <script type="text/javascript">
            var my_info= {};
            my_info["john"]="1a";
            my_info["joseph"]="2b";
            my_info["helen"]="3c";

            var val = JSON.stringify(my_info);

            alert(val);
        </script>
    </head>
    <body>
    </body>
</html>

JSFIDDLE (ignore the warnings)

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

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.