February 16 2016

WordPress Header error wp-includes/pluggable.php

Tagged Under : ,

Wordpress
When using wp_redirect() you will facing Header error “PHP Warning: Cannot modify header information – headers already sent by …… wp-includes/pluggable.php on line 1228”

To solve this problem you need to change the PHP.ini value. In PHP.ini find

February 16 2016

WordPress Ajax Example

Tagged Under : , ,

Wordpress
Below is the basic example of how to use AJAX in WordPress. It show you how to using javascript pass the variable to PHP function and then return back to javascript.

Javascript
var ajaxurl = '<?php echo admin_url() ?>admin-ajax.php';
jQuery(document).ready(function () {
	jQuery.ajax({
		url: ajaxurl,
		data: {
			//This action must same with the PHP function name
			"action": "ajax_request",
			"params": "wordpress ajax"
		},
		success:function(data) {
			//This is the result return from PHP function
			console.log(data);
		},
		error: function(errorThrown){
			//This is the error return
			console.log(errorThrown);
		}
	});
});

February 16 2016

Jquery only allow numeric (0-9) in HTML inputbox

Tagged Under :

jquery

Below is the function I use to only number, delete, backspace and tap are allow.
$(document).on("keydown", "#number", function(e) {
	var key = e.charCode || e.keyCode || 0;
	
	if (key == 8 || key == 9 || key == 13 || key == 46 || key == 110 || key == 190 || (key >= 35 && key <= 40) ||(key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
		return;
	} else {
		return false;
	}
});