What do you think about this idea?
Hi. I have an idea, may be you decide, that it's useful.
It's about request to JavaScript. I mean that if you want to post some
parameters to javascript on some xhtml you can't do this because of
philosophy of HTTP and URL.
If you use GET request every time server will answer, but it will
generate new content if you didn't request this page with this
parameters before. I mean that if you will request for
http://somedomain/some.php?modification=3
browser will put into the cash.
And if yiu request then
http://somedomain/some.php?modification=5
Of course, this page (its content) will missing in browser's cash.
It's right and truly philosophy,
but I think that we have to have some additional type of request.
For example, if some page is already in browser's cash. And I have
some url:
http://somedomain/some.php[ MAGIC: modification=5]
than this page will not have to request from server.
It just have to reload in browser. And javascript have to get
parameter modification.
Project, that I do now use this magic. Loophole is the "#".
I use it as follows.
url for main page:
http://onlyweb.ru/automobili/carprice/www/
url for modification=3:
http://onlyweb.ru/automobili/carprice/www/#modification:3
url for carClass=2
http://onlyweb.ru/automobili/carprice/www/#carClass:2
And if I wish to post more parameters I can separate they by dot('.')
For example:
http://somedomain/some.php#par0:dsf.par1:324
it's mean par0=dsf; par1=324.
And if I wish to post dot ('.') or ':' or not Latin symbols in
parameters' value, I just have to screen them.
In normal URL we use '%' for it:
http://somedomain/some.php?par0=%20%56%20
but after # in url we can use only '.', '-', '_', ':' and Latin
symbols.
I think, that we can use '_' for screening some symbols. For example:
http://somedomain/some.php#par0:_20_56_20
P.S.
I post this text because I decide use this magic request to javascript
after working with jQuery.
And if you find this technique useful, may be you will wish to add
this into jQuery or into some plugin.
For playing with this you can use this part of code (it works but
don't process '_' symbol such as '%' in GET request).
JSRequest = function(options) {
this.options = options;
return this.initialize();
};
JSRequest.prototype = {
initialize: function() {
this.processJSRequest();
},
processJSRequest: function() {
// TODO: throw exceptions
var hash = window.location.hash.replace(/^\#/, '');
var arrayOfStrings = jQuery.grep(hash.split('.'), function(n, i) {
return n != '';
});
this.request = {};
for(var i = 0; i < arrayOfStrings.length; i++) {
var pair = arrayOfStrings[i].split(':');
this.request[pair[0]] = pair[1];
}
}
}
var jsr = new JSRequest();
This code isn't clean, but it may help to understand the idia. Just
put it in some place of the xhtml page in script tag and than try to
get jsr.par0
when url is
...some.html#par0:2
it works. What do you think about it?