Get Data from JSON file into jQuery

roth514

I've tried to load data from a JSON file into jQuery.But nothing happened.Is there anything wrong with my JSON file define or the misuse of jQuery function? Here is my json file.

{ 
"jQueryquiz" :
 [
    {
        "title":"A",
        "answer":"asd"
        },
    {
        "title":"B",
        "answer":"qwe"
        },
    {
        "title":"C",
        "answer":"zxc"
    }
]   }

Here is my hmtl file:

<html>
<head>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

    <script>
        $(document).ready(function(){
            $('.button').click(function(){
                $.getJSON('quiz.json',function(data){

                    var html="";
                    html+=data.jQueryQuiz[0].title;
                    $('#results').html(html);
                });

            });
        });
    </script>
</head>
<body>

        <input type="button" class="button" value="Start!"/>

        <div id="results">

        </div>



</body>

roth514

The solution of my problem is to host the json file in some place like "myjson". The reason is just as Traveling Tech Guy said,"you can't read local files using AJAX".

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Get nested data from local JSON file

분류에서Dev

How to get data from JSON file?

분류에서Dev

Cannot getting data from external nested json file form jquery

분류에서Dev

Print data from json file

분류에서Dev

Get formatted data in shell script which is read from file containing JSON data

분류에서Dev

Jquery Get specific values from JSON result?

분류에서Dev

JQuery Autocomplete, populate with data from pHp json

분류에서Dev

Using jQuery to grab data from JSON

분류에서Dev

jQuery get path from data attribute

분류에서Dev

get property from data variable in ajax jQuery

분류에서Dev

Get value from JSON file in Swift

분류에서Dev

Accessing data from Wikidata JSON file

분류에서Dev

jQuery - How to get JSON array name from nested JSON

분류에서Dev

jQuery $.get() and $.ajax() doesn't get data from PHP

분류에서Dev

cant get jquery autocomplete to read in js file of data

분류에서Dev

How to load data from another file as an option value in JavaScript / jQuery?

분류에서Dev

jquery $.each nested in another $each. getting data from a JSON

분류에서Dev

Is it possible to get data from C#/Razor in jQuery by way of HTML?

분류에서Dev

How to get data from inputs and put them in an array using jQuery?

분류에서Dev

Using jquery in angular in returning data from $http.get request

분류에서Dev

Get data value from php array with autocomplete jquery/ajax

분류에서Dev

Retrieve data from JSON file and display images in a gallery

분류에서Dev

Read data from json file and set to combobox items

분류에서Dev

Appending JSON data from one file to another in Python

분류에서Dev

How to get data's from text file in c#

분류에서Dev

Get Data from Stripe Webhook JSON using PHP

분류에서Dev

How to get the Json data from eBay api to save in CSV format?

분류에서Dev

pull data from a file

분류에서Dev

JSON Data from api

Related 관련 기사

  1. 1

    Get nested data from local JSON file

  2. 2

    How to get data from JSON file?

  3. 3

    Cannot getting data from external nested json file form jquery

  4. 4

    Print data from json file

  5. 5

    Get formatted data in shell script which is read from file containing JSON data

  6. 6

    Jquery Get specific values from JSON result?

  7. 7

    JQuery Autocomplete, populate with data from pHp json

  8. 8

    Using jQuery to grab data from JSON

  9. 9

    jQuery get path from data attribute

  10. 10

    get property from data variable in ajax jQuery

  11. 11

    Get value from JSON file in Swift

  12. 12

    Accessing data from Wikidata JSON file

  13. 13

    jQuery - How to get JSON array name from nested JSON

  14. 14

    jQuery $.get() and $.ajax() doesn't get data from PHP

  15. 15

    cant get jquery autocomplete to read in js file of data

  16. 16

    How to load data from another file as an option value in JavaScript / jQuery?

  17. 17

    jquery $.each nested in another $each. getting data from a JSON

  18. 18

    Is it possible to get data from C#/Razor in jQuery by way of HTML?

  19. 19

    How to get data from inputs and put them in an array using jQuery?

  20. 20

    Using jquery in angular in returning data from $http.get request

  21. 21

    Get data value from php array with autocomplete jquery/ajax

  22. 22

    Retrieve data from JSON file and display images in a gallery

  23. 23

    Read data from json file and set to combobox items

  24. 24

    Appending JSON data from one file to another in Python

  25. 25

    How to get data's from text file in c#

  26. 26

    Get Data from Stripe Webhook JSON using PHP

  27. 27

    How to get the Json data from eBay api to save in CSV format?

  28. 28

    pull data from a file

  29. 29

    JSON Data from api

뜨겁다태그

보관