[jQuery] JSON- PHP generated JS-file question
Hello, i have just joined this group. First Google group i join !
I'm not native English speaking so sorry if i make some grammar
mistakes.
Anyway, the past 2 weeks i've been looking into JSON/AJAX functions of
jquery.
Now the reason for me doing that is that I want to make the following:
I want to have an input field that ask you for a code, let's say
"abc", my script should then automatically search for the price in the
database, so with an onblur i suppose.
Now i googled/read etc etc, and i came up with a script that worked.
It ran a PHP script, generated an array according to the SJON standard
that i found on the official website.
BUT after re-thinking what I was doing i thought to myself "what if I
have a database with 10 000 products. I would load a query each time
to search trough these 10 000 products/items. So I figured there must
be a better way. So i came up with the following idea:
lets run the PHP scripts one's a day and generate a .JS file
containing ALL the products in some sort of array readable for
$.getJson(). And this is where I get stuck:
how can I read trough the JS file and only select the price of the
item of witch I typed in the code "abc" ?
so if I have products.JS generated by PHP-script containing :
{"channel":{"items":[{"id":"1","prijs":"10","naam":"a"},
{"id":"2","prijs":"5","naam":"b"},
{"id":"3","prijs":"22","naam":"c"}]}}
how could I select the "prijs" of product "a" from that JS-file ? Is
it at all possible and if so how ?
Help would be greatly appreciated !