【问题标题】:AngularJS http.jsonp can't find JSON_CALLBACK from custom PHP proxy responseAngularJS http.jsonp 无法从自定义 PHP 代理响应中找到 JSON_CALLBACK
【发布时间】:2014-11-07 09:49:31
【问题描述】:

我正在尝试从 Readability 获得一个简单的 JSON 回复,使用 Readability 的 API 的直接链接可以正常工作,例如:

$http.jsonp('https://www.readability.com/api/content/v1/parser?url='+url+'&token='+token+'&callback=JSON_CALLBACK').success(function(data) { ... etc

但在使用我自己的“代理”时不起作用:

<?php
    header('Content-Type: application/json');
    print file_get_contents('https://www.readability.com/api/content/v1/parser?url='.urlencode($_GET['url']).'&token='.$token.'&callback=JSON_CALLBACK');
?>

与:

$http.jsonp('parser.php?url='+url).success(function(data) { ...

我也尝试过 curl 并复制所有标题等。我不明白,为什么 http.jsonp 无法从我自己的代理中找到变量 JSON_CALLBACK?

【问题讨论】:

    标签: javascript php json angularjs proxy


    【解决方案1】:

    JSON_CALLBACK 在调用 angular.callbackSomething 期间被替换,并且您的 PHP 使用硬编码的 JSON_CALLBACK,因此当 angular 尝试运行 callbackSomething 时,jsonp 没有使用此方法的函数,希望有意义

    print file_get_contents('https://www.readability.com/api/content/v1/parser?url='.urlencode($_GET['url']).'&token='.$token.'&callback='.$_GET['callback']);
    

    【讨论】:

      猜你喜欢
      • 2012-08-17
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多