【问题标题】:bit.ly API use issues (shorten, lookup, and clicks)bit.ly API 使用问题(缩短、查找和点击)
【发布时间】:2010-06-27 20:28:47
【问题描述】:

由于我的一部分时间不是专门用于 PHP 开发,所以我遇到了一个可能很容易解决的问题,但绝对没有日志(PHP 日志、浏览器 firebug 日志......)我很困惑.

这是我的代码;当我在测试东西时,它很原始。 index.php 文件:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  // You may specify partial version numbers, such as "1" or "1.3",
  //  with the same result. Doing so will automatically load the 
  //  latest version matching that partial revision pattern 
  //  (e.g. 1.3 would load 1.3.2 today and 1 would load 1.4.2).
  google.load("jquery", "1.4.2");
 
  google.setOnLoadCallback(function() {
    // Place init code here instead of $(document).ready()
    $("#shrelock").submit(function(){
        var url = $(this).attr('action');
        $.ajax({
          url: url,
          success: function(data) {
            alert(data);
          }
        });
        return false;
    });
  });
</script>

    <form id="shrelock" action='stats.php' method='get'>
        <input type="text" name="url"/>
    </form>

现在是 stats.php 文件:

include("bitly.php");
if ( isset($_POST["url"])   ){
    $urlToCheck = $_POST["url"];
    $bitly = new bitly('myLogin', 'myKey'); 
    print $bitly->shorten($urlToCheck);

}

【问题讨论】:

    标签: php api bit.ly


    【解决方案1】:

    我不确定您的问题是什么,但我确实看到您的代码存在一些问题。

    您执行的 ajax 请求使用 GET,而服务器端代码似乎需要 POST 而且你忘了在ajax调用中发送'url'参数。

    $.ajax({
         url: url,
         type: 'POST',
         data: 'url=' + $('#shrelock input[name="url"]').val(),
         success: function(data) {
           alert(data);
         }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 2019-09-22
      • 2011-08-20
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多