Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Obtain and using data, from .json file

    Hello

    Using jquery, i obtain some data from .json file and a want alert this data after click on the div tag, how make this ?
    this is an approximate example, what i want?

    Code:
    $.getJSON("mydata.json").success ( function (myJson) {
    		 myVariable = myJson["Positions"][0]["x"];
         }
    );
    
    
    function muClick () {
    	alert(myVariable );
    }
    
    
    
    <body>
    <div onclick="muClick();">  text text text  </div>
    Please help me

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    You shouldn't really care how the data looks in the alert since you will be the only one to see it - since alert is a debugging command that should be removed before your script goes live - since you will not want people using the checkbox in the alert that turns off JavaScript or all the subsequent alerts (depending on which browser they are using).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •