0

I'm trying to call a json file, but my function isnt returning anything.

index.html

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script>$(document).ready(function(){
    $.getJSON( 'ebooks.json', function( fb ) {
        alert(fb);
    });          
});
}

ebooks.json

{
"title" : "software design"
}
1
  • 4
    If there's no alert at all, the first thing to do is to open your console and look for errors, if there are non, the second thing to do would be to add a fail() handler and see what the problem is. Commented Nov 23, 2013 at 16:16

2 Answers 2

1

Can you try this, You have added extra } in your code,

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

 <script>

    $(document).ready(function(){
        $.getJSON( 'ebooks.json', function( fb ) {
            alert(fb);
        });          
    });

</script>

You can able to find this errors using in Firefox Tools->Web Developer ->Error Console or CTRL+SHIFT+J

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

1 Comment

NP. Glad to help you :)
0

Don't know why to be honest, but it only worked when I declared the ready() function separately and passed this function to $(document).ready.

<html>
<body>
    <h1 id="titel">Title</h1>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript">
    function ready() {
        $.getJSON( 'ebooks.json', function( fb ) {
            alert(fb.title);
        });          
    };

    $(document).ready(ready());

</script>
</body>
</html>

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.