开发者

bit.ly API use issues (shorten, lookup, and clicks)

as part of my time isn't dedicate开发者_运维技巧d to PHP dev, I'm having an issue which is probably easy to solve, but having absolutely no logs (PHP logs, browser firebug logs...) I'm pretty stuck.

Here's my code; as I'm testing stuff, it's pretty raw. The index.php file :

<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>

Now the stats.php file :

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

}


I'm not sure what your question is, but I do see a few problems with your code.

The ajax request you perform uses GET while the serverside code seems to expect a POST and also you forgot to send the 'url' parameter in the ajax call.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜