javascript - JS Click 上的 PHP 函数?

标签 javascript php jquery twitter-bootstrap

我有一个按钮,可以将链接复制到剪贴板,但它已使用 bit.ly 缩短了。目前我已经有了它,因此它在页面加载时创建了 bit.ly 链接,这看起来有点困惑,所以我只是想知道如何让它仅在复制到剪贴板时才执行此操作?

var client = new ZeroClipboard( document.getElementById("copy-link"), {
moviePath: "ZeroClipboard.swf"
} );

client.on( "load", function(client) {
// alert( "movie is loaded" );

    client.on( "complete", function(client, args) {
        // `this` is the element that was clicked
        $.gritter.add({
            // (string | mandatory) the heading of the notification
            title: 'Link Copied',
            // (string | mandatory) the text inside the notification
            text: 'Link has been copied to your clipboard'
        });
        $('[data-toggle="dropdown"]').parent().removeClass('open');
    } );
} );

这是我的 PHP

<?php

$url = Router::url(null, true);
if ($this->UserAuth->isLogged()) {
    $url .= '?shareref=' . $var['User']['id'] . '';
}
$shortlink = bitly_v3_shorten($url, 'bit.ly');

?>

最佳答案

JQuery Ajax 将是您的最佳选择:http://api.jquery.com/jquery.ajax/ - 创建它,以便在您单击按钮时运行 PHP。

关于javascript - JS Click 上的 PHP 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21555822/

相关文章:

javascript - 如何在js中匹配两个id时使用ignorecase

javascript - 用于更改元素上的 css 的 Javascript 是什么?

php - 插入获取数组数据到新数据库

javascript - Ajax 自动刷新导致我的 jquery 嵌入脚本无休止地重复

javascript - 加载脚本后调用javascript函数

javascript - 我怎样才能使这个标记系统可排序?

javascript - 从十进制转换为十六进制时缺少前导零

javascript - 如何缩短 jQuery 函数?

php - 这个 mySQL 存储过程有效吗?

php - 在php上搜索多个小写字母