csdn产品小助手 2016-07-07 06:35 采纳率: 0%
浏览 42

parseInt值无错误

I have an AJAX request that does nothing and I don't know why. It doesn't give me any error.my code:

$("#idButton").click(function(){
    $.ajax({
            type: "GET",
            url: "https://api.fixer.io/latest?base=EUR",
            data: {},
            success: function(data) {
                     $("#idUsd").val(parseInt(data['rates']['USD']) * 
                     parseInt($("#idEur").val())); //I think the error is here
            },

            error: function(x, e) { console.log(e); }
    });
});

Can anyone help me?

EDIT:

screenshot

  • 写回答

3条回答 默认 最新

  • weixin_33716941 2016-07-07 06:44
    关注

    Your AJAX request is inside a click handler. I believe you have defined the click handler before you have actually added #idButton to the HTML. You need to make sure that the element already exists when the handler is defined, possibly putting it into $(function() {}) or to use .on() which will register the handler in future element creation as well.

    Case 1:

    You have a script tag inside your head and you define #idButton inside body. In this case this code should solve the problem:

    $(function() {
        $("#idButton").click(function(e) {/*Your handler*/});
    });
    

    Case 2:

    #idButton is created and added at runtime. In that case

    $('body).on('click', '#idButton', function(e) {/*Your handler*/});
    

    should solve the problem. Ideally switch body to the lowest node selector in the tree already existent when you define the handler and which contains the button.

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码