I am writing a validation mechanizm for my website. Some code is used with Javascript and ajax to validate (mostly lengths of) strings. And some other code is used in php on the server side.
Both PHP and Javascript need to use the same vars, say MAX_USERNAME_LENGTH
.
So that they stay in sync, and save on development time up front.
I was thinking of using JSON. But after researhing a little I noticed that:
$.getJSON("http://myurl.com/vars.json", function(json) {
alert(json['MAX_USERNAME_LENGTH']);
})
for starters, this for some reason won't access a local location as ../includes/vars.json
, and returns 404 for some reason....
- I was thinking, if I put this in the
$(document).ready(function ()
then all the code would run, but the vars themselves would not have loaded if the network was slow....
Is there a way to simply do something like :
var json=parseJsonFromLocalFile("../includes/vars.json");
I need this also for the php, but there I think it would be easier using json_decode()
Thanks in advance!!!