In questo articolo vedremo come eseguire una routine in base al valore di una query string con jQuery.
Teniamo presente che una query string implica il reload della pagina. Quindi avremo:
"use strict";
(function( $ ) {
$.Loader = function() {
this.init();
};
$.Loader.prototype = {
init: function() {
if( location.search ) {
if( /method=/.test( location.search ) ) {
var parts = location.search.split( "=" );
var method = parts[1];
if( typeof this.methods[method] === "function" ) {
this.methods[method]();
}
}
}
},
methods: {
test: function() {
console.log( "test" );
}
}
};
})( jQuery );
Quindi possiamo usare un URL come /pagina/?method=test
.