Skip to main content

Posts

Showing posts from November 24, 2019

Loading gif while waiting for AJAX response without any button trigger

When there is no trigger for loading gif we can use setTimeout dunction to display image < img src = "loading.GIF" id = "img" style = "display:none" / > < script > setTimeout( function (){$( '#img' ).show();}, 30 ); $.ajax({ type : 'POST' , url : ' ajaxfile.php' , data : {id : 123 }, success : function (response) { $( '#img' ).hide() }, error : function (response,status) { alert( 'Error' ); } }); < /script>

Check curl status

We can check curl status as below $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,'https://esoftsolutions4u.blogspot.com'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); If $http_status = 200,then we have correct response. If ($http_status ="" || $http_status ="failed" ) then we have failed response or some error in the response.