0
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="js/jquery-1.3.2-vsdoc.js"></script>
<script type="text/javascript">
    $(function() {
       

        $("#Button1").click(function() {
        		
           $.getJSON("ticketPriceInArray.js", 
	    function(json) {
	   var ticketPriceArray=[json.tickets[0].price, json.tickets[1].price, json.tickets[2].price, json.tickets[3].price, json.tickets[4].price, json.tickets[5].price];
                               
	    	                 alert(json.tickets[0].type);
                                     
             var inputWord =$("#keyword").val();
            	 if (inputWord=="A"){$("#result").text(ticketPriceArray[0]);}   
            	 if (inputWord=="B"){$("#result").text(ticketPriceArray[1]);}
            	 if (inputWord=="C"){$("#result").text(ticketPriceArray[2]);}	
            	 if (inputWord=="D"){$("#result").text(ticketPriceArray[3]);}	
            	 if (inputWord=="E"){$("#result").text(ticketPriceArray[4]);}	
            	 if (inputWord=="F"){$("#result").text(ticketPriceArray[5]);}		
	    });
             
        });
    });    
</script>

Here is "ticketPriceInArray.js"

{ 
	"tickets":[
          {
	    "type":"A Ticket",
	    "price":220,
  	  },

	  {
	    "type":"B Ticket",
	    "price":180,
  	  },

	  {
	    "type":"C Ticket",
	    "price":120,
  	  },

	  {
	    "type":"D Ticket",
	    "price":100,
  	  },

	  {
	    "type":"E Ticket",
	    "price":80,
  	  },

	  {
	    "type":"F Ticket",
	    "price":50,
  	  }
      ]
}

This is a simple html where when the corresponding text inputed, the corresponding ticket price will show in the html after a button-click. All the ticket info is stored in a .json file named "ticketPriceInArray.js" and I have been trying to read it using $.getJSON(), but unfortunately I haven't been able to get any success. The weird thing is I didn't get any warning on anything so I couldn't fix it. Please see if you can give me any suggestions. Thank you.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by twiss
0

jQuery doesn't raise an error often, as IE sometimes displays an error message box and they didn't want that to happen. You'll have to do some logging, what doesn't work? As a start, put console.log(json); after line 10 and look in you're browser's console if you have the data. What does the alert say? Et cetera.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.