Sunday 27 November 2016

Get geo location using javascript in destop and leptop or computer


Get geo location using javascript in destop and leptop or computer



 <p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(getAddress);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";}
    }
function getAddress(position){

  var lat = position.coords.latitude;
  var lon = position.coords.longitude;

  //grab address via Google API using your position
  var apiurl = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+lat+','+lon+'&sensor=true';


  //make the Ajax request
  var xhr = new XMLHttpRequest();

  xhr.open("GET", apiurl);
  xhr.onload = function() {
  var result = JSON.parse(xhr.responseText)

    //if we make a successful request and it returns an address
  if(this.status==200){
  //get formatted address from https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding
  //var result = JSON.parse(xhr.responseText).contents.results[0].formatted_address;
  console.log(result.results[0]['formatted_address']);
alert(result.results[0]['formatted_address']);
      } else {
      //send some general error
     
      }

  }

  xhr.send();
               
}
</script>

Get geo location using javascript in destop and leptop or computer

Tuesday 15 November 2016

jquery replace all single or double quotes

hello Here simple example of replace single and doble quotes using jquery replace function.

we can use jquery replace function to replace single and double quotes.

example below

jquery replace all single or double quotes

we can pass two parameter to replace single quotes in string

//replace all single quotes
var myStr = myStr.replace(/'/g, '');

//replace all double quotes
var myStr = myStr.replace(/"/g, '');

//or abit of fun, replace single quotes with double quotes
var myStr = myStr.replace(/'/g, '"');

//or vice versa, replace double quotes with single quotes
var myStr = myStr.replace(/"/g, ''');

jquery replace all single or double quotes

php and curl get put post delete example

php and  curl get put post delete example

hello here how to pass value in post and put curl in php. 
see the below example.

/*  PUT CURL EXAMPLE (php and  curl get put post delete example) */

$data = array('email'=>'test@test.com','password'=>'test');
$data_json = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);


/*  POST CURL EXAMPLE  (php and  curl get put post delete example)*/


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);

/*  GET CURL EXAMPLE  (php and  curl get put post delete example)*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo "<pre>";
print_r($response);

/*DELETE CURL EXAMPLE  (php and  curl get put post delete example)*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);