Tuesday, 8 September 2015

What are differences between $(document).ready and $(window).load?


What are differences between $(document).ready and $(window).load?

$(document).ready();
$(document).ready(function() {
 /** Add your code here **/
            


/** Add your code here **/

 console.log("HTML Document is fully load. HTML, javaScript and CSS is fully loaded.");
});

JavaScript code written inside $(document).ready will be called when HTML Document is fully loaded. It means JavaScript code will be called just after HTML, JavaScript & CSS is fully loaded.



$(window).load();
$(window).load(function() { 
 /** Add your code here **/
            


/** Add your code here **/


 console.log("Web page fully Loaded. HTML, Javascript, CSS, Images, Iframes and objects are fully loaded.");
});


JavaScript code written inside $(window).load will be called when Web page fully Loaded. It means JavaScript code will be called just after HTML, Javascript, CSS, Images, Iframes and objects are fully loaded.

Following document ready have same meaning and work as same.
$(document).ready(function(){

});
OR
$(function(){

});
OR
$(document).on('ready', function(){
})



Monday, 7 September 2015

How to Detect Request type in PHP

How to Detect Request type (GET OR Post ) in PHP

Question:How to Detect Request type (Get OR Post) in PHP?
$method = $_SERVER['REQUEST_METHOD'];
try {
    switch ($method) {
        case 'GET':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'POST':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'PUT':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'HEAD':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'DELETE':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'OPTIONS':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        default:
            echo "$method method not defined";
            break;
    }
} catch (Exception $e) {
    echo $e->getMessage();
}



Question: How to get all post data in PHP?
$postData = array();
if(!empty($_POST)){
    $postData = $_POST;
}
print_r($postData );



Question: How to get all GET data in PHP?
$getData = array();
if(!empty($_GET)){
    $getData = $_GET;
}
print_r($getData );



Question: How to get Document root path in PHP?
echo $_SERVER['DOCUMENT_ROOT'];



Question: How to get Client Ip-Address in PHP?
echo $_SERVER['REMOTE_ADDR'];