I was trying to use AJAX call to get JSON result of Bing News Search, however it doesn't work out.
My PHP code is:
<?php
if (isset($_GET['symbol'])){
$accountKey = 'myaccountkey';
$WebSearchURL = $_GET['symbol'];
$context = stream_context_create(array(
'http' => array(
'request_fulluri' => true,
'header' => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)
)
));
$response = file_get_contents($WebSearchURL, 0, $context);
echo $response;
}
?>
And my AJAX code is:
var bingquery = "symbol=" + "https://api.datamarket.azure.com/Bing/Search/v1/News?Query=%27" + $('#query').val() + "%27&$format=json";
console.log(bingquery);
$.ajax({
url: "bingsearch.php",
method: "get",
dataType: "json",
data: bingquery,
success: function(jsondata){
console.log('***Test for News Feeds***');
console.log(jsondata);
//console shows nothing here, AJAX doesn't succeed
}
});
Could you please give me some hint on this? Thank you so much!