0

我试图使用 AJAX 调用来获取 Bing 新闻搜索的 JSON 结果,但是它没有成功。

我的 PHP 代码是:

<?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;
} 
?>

我的 AJAX 代码是:

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
        }
        });

你能给我一些提示吗?太感谢了!

4

0 回答 0