Skip to main content

Posts

Showing posts from November, 2014

Jquery Ajax method

AJAX = Asynchronous JavaScript and XML. AJAX is about loading data in the background and display it on the webpage, without reloading the whole page. The ajax() method is used to perform an AJAX (asynchronous HTTP) request. Notes: Asynchronous means that the script will send a request to the server, and continue it's execution without waiting for the reply. As soon as reply is received a browser event is fired, which in turn allows the script to execute associated actions. The serialize() method creates a URL encoded text string by serializing form values readyState  Holds the status of the XMLHttpRequest. Changes from 0 to 4: 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready The parameters specifies: beforeSend(xhr): A function to run before the request is sent eg: beforeSend: function() {     xhr.setRequestHeader("Accept", "text/javascr...

Fetch IP address & country

Function to fetch ip address function get_ip() { $ipaddress = ''; if (getenv('HTTP_CLIENT_IP')) $ipaddress = getenv('HTTP_CLIENT_IP'); else if(getenv('HTTP_X_FORWARDED_FOR')) $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); else if(getenv('HTTP_X_FORWARDED')) $ipaddress = getenv('HTTP_X_FORWARDED'); else if(getenv('HTTP_FORWARDED_FOR')) $ipaddress = getenv('HTTP_FORWARDED_FOR'); else if(getenv('HTTP_FORWARDED'))   $ipaddress = getenv('HTTP_FORWARDED'); else if(getenv('REMOTE_ADDR')) $ipaddress = getenv('REMOTE_ADDR'); else $ipaddress = 'UNKNOWN'; return $ipaddress; } Method to fetch countryname & city  $id=trim('122.177.145.202'); $result  = array('country'=>'', 'city'=>''); $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=...

Change in bootstrap datatable

How to change default sorting & disable sorting.   $('.dataTables-example').dataTable({ "order": [[ 7, "desc" ]], columnDefs: [   { orderable: false, "targets": -1 } ] }); Notes: 1.It will change default sorting to 7 column 2. Disable sorting form last column.

PHP XML handling

songs.xml <songs>     <song dateplayed="2011-07-24 19:40:26">         <title>I left my heart on Europa</title>         <artist>Ship of Nomads</artist>     </song>     <song dateplayed="2011-07-24 19:27:42">         <title>Oh Ganymede</title>         <artist>Beefachanga</artist>     </song>     <song dateplayed="2011-07-24 19:23:50">         <title>Kallichore</title>         <artist>Jewitt K. Sheppard</artist>     </song> </songs> eg <?php     $mysongs = simplexml_load_file('songs.xml');     echo "<ul id="songlist">n";     foreach ($mysongs as $songinfo):         $title=$songinfo->title;       ...