尝试根据输入获得分数值但失败

时间:2017-06-11 12:14:07

标签: javascript jquery html

在问这个之前,我已经尝试成功获得分数值

这是我的剧本

<script>		 
    $.ajax({
        type: "POST",
        url: "https://example.com/paylist.php?acc=useraccount&json=1",
        dataType: "JSON",
        success: function (data) {
            $('#total').text(data.pending[0].pending);
        }
     });
</script>

成功抓取data.pending[0].pending 我想创建一个输入框让我的博客访问者获得自己帐户的分数,但它失败了

我将脚本更改为

<script>		
function onClaim(token) {
    $.ajax({
        type: "POST",
        url: "https://example.com/paylist.php? 
                       acc='+useraccount+'&json=1",
        dataType: "JSON",
        success: function (data) {
            $('#total').text(data.pending[0].pending);
        }
    });
}

这是我的输入框和搜索按钮

<div> 
<input required="" type="text" style="width: 90%; max-width: 600px; text-   align: center;" name="useraccount" id="useraccount" placeholder="Your account"    value=""> 
</div> 
<div> 
<button style="display: block; margin-left: auto; margin-right: auto;"    id="findbutton"  data-callback="onClaim">Find</button> 
</div> 
<center><a  style="color: rgb(102, 102, 102);">score: </a><span id="total"  style="color: rgb(102, 102, 102);"></span></center>

我尝试运行时没有收到任何错误消息。

抱歉我的英语不好。

1 个答案:

答案 0 :(得分:0)

首先获取useraccount值var useraccount = $("#useraccount").val();

然后您的AJAX网址应如下所示:

url: "https://example.com/paylist.php?acc="+useraccount+"&json=1",