weixin_33716941 2015-06-07 16:40 采纳率: 0%
浏览 19

Ajax脚本中的语法错误

I'm having a hard time arranging my ajax script very well and i thinking if i could help some help here

$(document).ready(function() {
      $follow_container = $('#follow_container');
      var follow = localStorage.getItem('follow');
      if (follow !== null) {
        $follow_container.html(follow).show()
      }
      $('.followclick').on('click', function(event) {
            if (follow == null) {
              $('#follow_container').load('http://mysite/news.asp', function() {
                  localStorage.setItem('follow', $follow_container.html());
                }
              });
  • 写回答

1条回答 默认 最新

  • weixin_33725239 2015-06-07 16:52
    关注

    Every time you open a block of code (using a {), you also have to close it. Every time you open a function call (using a (), you also have to close it. You code just sort of trails off without actually closing anything.

    When you do this:

    if (follow == null) {
    

    Somewhere, later in the code, at the end of that if block, you need to do this:

    }
    

    When you do this:

    on(
    

    Somewhere, later, you need to do this:

    )
    

    So, putting all of that together... close your code blocks:

    $(document).ready(function() {
        $follow_container = $('#follow_container');
        var follow = localStorage.getItem('follow');
        if (follow !== null) {
            $follow_container.html(follow).show()
        }
        $('.followclick').on('click', function(event) {
            if (follow == null) {
                $('#follow_container').load('http://mysite/news.asp', function() {
                    localStorage.setItem('follow', $follow_container.html());
                });
            }
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突