i'am trying to send getVenueFromFS returned value to RealTimeUpdate.php page without success. the value is printed correctly using the alert method but i cant send it, once the project is complete it should be put on uni servers, they dont have ajax or an other 3rd party's. the function: `
<script type="text/javascript">
<!--
function getVenueFromFS() {
var venueFSID = "4a1ef31ff964a520ef7b1fe3";
var xhttp = new XMLHttpRequest();
var url = 'https://api.foursquare.com/v2/venues/'+venueFSID+'?oauth_token=MOBUA5IQL5PJGHPMAEU22OQDWIJJWF425XO5JLOSFHGJOTAC&v=20161224';
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
var obj = JSON.parse(xhttp.responseText);
alert("venue number: " + venueFSID + " was retrieved successfully");
alert("like count: " + obj['response']['venue']['likes']
return obj['response']['venue']['likes']['count'];
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
//-->
</script>`
but using //$.post('RealTimeUpdate.php', {variable: javascriptVariable});
or
//window.location.href = "RealTimeUpdate.php?name=" + javascriptVariable; wont work.
}
Soultion: i put the script inside the body, and not the head, disable the returned value and wrote another function that will retrieved it, and used setTimeout , thanks everybody
function myJavascriptFunction() {
var data = getVenueFromFS();
//alert("NEW" + data);
//$.post('RealTimeUpdate.php', {variable: data});
//window.location.href = "RealTimeUpdate.php?name=" + data;
var FSID = document.getElementById('FsId').value;
window.location.href = "RealTimeUpdate.php?name=" + data + "&FSID=" + FSID;
}
function getVenueFromFS() {
var obj
//var venueFSID = document.getElementById('FsId').value;
var venueFSID = "4a1ef31ff964a520ef7b1fe3";
var xhttp = new XMLHttpRequest();
var url = 'https://api.foursquare.com/v2/venues/'+venueFSID+'?oauth_token=MOBUA5IQL5PJGHPMAEU22OQDWIJJWF425XO5JLOSFHGJOTAC&v=20161224';
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
obj = JSON.parse(xhttp.responseText);
alert("venue number: " + venueFSID + " was retrieved successfully");
alert("new like count: " + obj['response']['venue']['likes']['count']);
parameter = obj['response']['venue']['likes']['count'];
setTimeout(function(){ window.location.href = "RealTimeUpdate.php?name=" + parameter }, 6000);
// return obj['response']['venue']['likes']['count'];
}
};
xhttp.open("GET", url, false);
xhttp.send();`enter code here`
return obj['response']['venue']['likes']['count'];
}