I have an API that is available only in javascript (no PHP). It fetches some data of which I made a JSON string. What I need to know is how do I read this string in other page?
I tried using following :
$json = file_get_contents($url);
but of course the string I get is not JSON but is actually the javascript code that will generate json in original page. Any suggestions ? Thank you.
P.S. I also tried set cookie + redirect. Though that worked, I'd like to know a better solution.
Here is the javascript code
function searchComplete() {
if (imageSearch.results && imageSearch.results.length > 0)
{
var contentDiv = document.getElementById('content');
contentDiv.innerHTML = '';
var results = imageSearch.results;
var data = "{['data' : [\n";
for (var i = 0; i < results.length; i++) {
//var result = results[i];
var result = results[i];
data += "{\n";
data += "'url' : '"+result.url+"'";
data += "\n},\n";
}
data += "]]}";
setCookie("datajson", data, 1); // This is how i set the cookie and redirected
window.location = "JSPHP.php?data="+data;
document.getElementById('body').innerHTML = data;
}
}