Tuesday, December 6, 2011

Simple browser cache bypass

I need a quick solution to go over a browser page caching problem...
After some research..... I look for this quick solution....
Add a random argument to your url..:

var forwardUrl = 'http://yourcachedpage.html?' + (new Date()).getTime();

Bye...



Thursday, December 1, 2011

JSON-P: quick and dirty how-to

JSONP borns to provides cross-domain resources interoperability....
It simply works by creating and adding a <script> element tag in runtime...

Here is a simple implementation.....

function methodA () {
//your code.....
//and call to remote(and with other domain) url.....
jsonp_request('http://another_site:1234/YourServletOrOtherService');
}


//
//http://another_site:1234/YourServletOrOtherService
//will returns a string similar to this...
//                    methodB([{"result":"pippo"}])
//
//methodB
//                 stay for the next js method that will be called....
//
//{"result":"pippo"}
//                 stay for json data structure to send as returns data
//
//


function jsonp_request (url) {
    var head = document.getElementsByTagName("head")[0];
    var script = document.createElement("SCRIPT");
    script.type = "text/javascript";
    script.src = url ; 
    head.appendChild(script);    
}



function methodB (data) {
    var current_result = data[0].result;
    alert (current_result) ;
    //elaborate your data json structure..... a single value or an array of values.....
}


Reference url....: http://json-p.org

Bye....

Simple Reg-Exp...

Two simple regexp.......
for match string pippo.pluto
^.*(?:pippo.pluto).*$

or for not match string pippo.pluto
^((?!pippo.pluto).)*$

Useful links....
to test.....
http://www.regular-expressions.info/javascriptexample.html
to search ready-to-use reg expressions....
http://regexlib.com