在JQuery中解析Json得到错误“;ReferenceError:href未定义";


Parsing Json in JQuery get error "ReferenceError: href is not defined"

当我尝试从connection.php解析json时,使用的是jquery:

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="jquery-2.1.1.js"></script>
    <script type="text/javascript">
    $("document").ready(function() {
        $.getJSON('connection.php', {
            cid: href,
            format: 'json'
        }, function(data) {
            $.each(data, function(index, element) {
                /* mengisikan table dari hasil json */
                $('#tabledata').find('tbody')
                    .append($('<tr>')
                        .append(
                            '<td>' + data.sys + '</td>' +
                            '<td>' + element.procid + '</td>'
                        )
                    );
            });
        });
    });
    </script>
</head>
</html>

我得到错误

ReferenceError:href未定义$.getJSON('connection.php',{cid:href,format:'json'},函数(数据){

如果要将cid值作为字符串href发送,请在href周围使用引号。
$.getJSON('connection.php', { cid: 'href', format:'json' }, function(data) {
//                                 ^    ^

如果href是可变的,请确保它在getJSON的范围内。

$("document").ready(function() {
    var href = 'www.google.com'; // Defined here
    $.getJSON('connection.php', { cid:href, format:'json' }