【问题标题】:Show data obtained from field in ajax by console通过控制台显示从ajax中的字段获取的数据
【发布时间】:2020-06-19 18:45:50
【问题描述】:

我是使用 ajax 和 PHP 的新手,我需要按字段发送数据并通过控制台显示,但它对我不起作用。你能帮我用什么版本的 jquery 来使脚本工作吗?

<script src="https://code.jquery.com/jquery-1.10.2.js"></script> 

<input type="text" name="box" id="box" class="box" value="">
<input type="button" name="boton01" id="boton01" value="Buttom">

$(document).ready(function() {
    $('#boton01').click(function(){
        var result=$('#box').val();
        console.log(result);
    })
});

主机展示

Uncaught ReferenceError: $ is not defined

【问题讨论】:

    标签: php jquery ajax console


    【解决方案1】:

    您需要将jQuery$“别名”才能使用它,否则您应该能够将我们的$jQuery 交换,所有这些都应该适合您:

    // use self invoking function and pass in jQuery then alias it with $
    (function($){
        $(document).ready(function() {
            $('#boton01').click(function(){
                var result = $('#box').val();
                console.log(result);
            });
        });
    })(jQuery);
    

    // use jQuery in place of $
    jQuery(document).ready(function() {
        jQuery('#boton01').click(function(){
            var result = jQuery('#box').val();
            console.log(result);
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2015-01-03
      • 1970-01-01
      • 2022-11-26
      • 2018-10-11
      • 1970-01-01
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 2019-04-21
      相关资源
      最近更新 更多