Deprecated: idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated in /var/www/legtux.org/users/seconde/www/blog/inc/boot.php on line 200
Rwanito Blog

Rwanito Blog

Ici, rien de plus qu'un mémo des meilleures fonctions que je trouve!

Aucun commentaire

Retrouver la Super Globale GET de PHP en JS

function $_GET(param) {
	var vars = {};
	window.location.href.replace( location.hash, '' ).replace( 
		/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
		function( m, key, value ) { // callback
			vars[key] = value !== undefined ? value : '';
		}
	);

	if ( param ) {
		return vars[param] ? vars[param] : null;	
	}
	return vars;
}

1 commentaire

GitHub Jquery Ajax Progression

$.ajax({
    method: 'GET',
    url: 'data/bird.json',
    dataType: 'json',
    success: function() { },
    error: function() { },
    progress: function(e) {
        //make sure we can compute the length
        if(e.lengthComputable) {
            //calculate the percentage loaded
            var pct = (e.loaded / e.total) * 100;

            //log percentage loaded
            console.log(pct);
        }
        //this usually happens when Content-Length isn't set
        else {
            console.warn('Content Length not reported!');
        }
    }
});

Ne pas oublié dans le PHP :

header('Content-Type: application/json');
header("Content-length: $size");

où $size est la taille du fichier JSON

Aucun commentaire
function getBase64Image(img) { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var dataURL = canvas.toDataURL("image/png"); return dataURL.replace(/^data:image\/(png|jpg);base64,/, ""); }

var base64 = getBase64Image(document.getElementById("imageid"));

Aucun commentaire

function shuffle(string) { 
    var parts = string.split(''); for (var i = parts.length; i > 0;) { var random = parseInt(Math.random() * i); var temp = parts[--i]; parts[i] = parts[random]; parts[random] = temp; } 

    return parts.join(''); 
}

alert(shuffle('abcdef'));