Search code examples
javascriptphpjsonhref

Javascript Variable to Php json decoded


Actually i've used this script to get the profile picture of instagram user

<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
  <script type="text/javascript">
var user_id = <? echo $page_id; ?>;
var url = "https://api.instagram.com/v1/users/"+user_id+"?client_id=775829274b6f48c1ac2bf218dda60e16&callback=?";
$.getJSON(url, function(data) {
    $("body").append("<img src='"+data.data.profile_picture+"' />");

}
);

  </script>

The Output of this script is 100% what i need. All i need now is to take the image link to a PHP variable which is (+data.data.profile_picture+)

if tried to reload the same page with + ?link="+data.data.profile_picture+" so i can grab it with $_GET['link'] Like this:

window.location.href = location.href + '?link="+data.data.profile_picture+";

but it doesn't .. What should i do to pass this javascript variable to a PHP variable.


Solution

  • Try This

    window.location.href = location.href + '?link='+data.data.profile_picture;