获取值并使用Ajax发送url

时间:2013-11-28 19:37:03

标签: javascript html ajax

我想获取文本字段中的数字并将其发送到Url methode GET;

$(document).ready(function () {
            $("#go").click(function() {
                var n = document.getElementById('nombre').value;
                alert("Chess.php?number=9");
                $('#chess').load("Chess.php?number="+n);    
            });

值:

<input type="text" name="nombre" id="nombre">

3 个答案:

答案 0 :(得分:2)

请尝试使用以下代码:

$(document).ready(function () {
    $('#go').click(function() {
        $.get('Chess.php', { number: $('#nombre').val() } );
    });
});

PS:陌生人称为nombre的属性值和名为number的字段。改变这一点。其他提示不要使用大写字母作为网址,只使用'chess.php'。

我希望能帮助你。

答案 1 :(得分:1)

缺少}) ...

另外,您必须在脚本的head部分添加以下内容:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function () 
{
    $("#go").click(function() 
    {
        var n = document.getElementById('nombre').value;
        alert("Chess.php?number=9");
        $('#chess').load("Chess.php?number="+n);    
    })
});

</script>

答案 2 :(得分:0)

现在就像这样

$(document).ready(function () {
    $("#go").click(function() {
        $('#chess').load("Chess.php?number="+document.getElementById('nombre').value);
    });
});