title: How to get json data to script variables?
body: <p>I try to fetch json data my from url but it's not working. I want that json array values pass to script variables userid, username, usermobile, useremail and $userpassword so that I can them to my ajax variables.</p>
  
  <pre><code>&lt;script src="../js/jquery2.0.3.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      var text=[
          {
      "userid" : "dfhsfgdsjfghdjsghdjs",
      "username" :"Md Mubarik",
      "usermobile" : 9871492281,
      "useremail" :"mdmubarik05@gmail.com",
      "userpassword" : "#$md786"
  }];
  
  &lt;/script&gt;
  &lt;?php
  
      $data=array();
  
      $url="http://localhost/restapi/user/insertuser.php";
  
      $json_data=file_get_contents($url);
  
      $data=json_decode($json_data);
  
      $userid=$data-&gt;userid;
      $username=$data-&gt;username;
      $usermobile=$data-&gt;usermobile;
      $useremail=$data-&gt;useremail;
      $userpassword=$data-&gt;userpassword;
  ?&gt;
  &lt;script&gt;
  
      var userid=&lt;?php echo $userid;?&gt;;
      var username=&lt;?php echo $username;?&gt;;
      var usermobile=&lt;?php echo $usermobile;?&gt;;
      var useremail=&lt;?php echo $useremail;?&gt;;
      var password=&lt;?php echo $userpassword;?&gt;;
  $(document).ready(function(){
  
          $.ajax({
                              type:'POST',
                              url:'insertuserdata.php',
                              data:{'userid':userid,'username':username,'usermobile':usermobile,'useremail':useremail,'password':password},
                              success: function(data){
                                  alert(data);
  
                              }
  
              });
  
   });
  &lt;/script&gt;
  </code></pre>