开发者

Javascript parse error

I'm using jQuery to do an AJAX POST request. Here's the cod开发者_开发百科e

jQuery(document).ready(function() {
     jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
var refreshId = setInterval(function() {
  jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
}, 30000);
});
jQuery(function() {  
jQuery(".button").click(function() {
var dataString = 'tweet='+ tweet;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "/index.php?app=ccs&module=pages&section=pages&id=7",
data: dataString,
success: function() {
    $('#postsuccess').html("<b>Post Successful</b>");
  }); // this is where the parse error is
}
});
return false;
});  
});

Any ideas?


That's why formatting code is important

jQuery(document).ready(function() {
    jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
    var refreshId = setInterval(function() {
        jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
    },
    30000);
});
jQuery(function() {
    jQuery(".button").click(function() {
        var dataString = 'tweet=' + tweet;
        //alert (dataString);return false;
        $.ajax({
            type: "POST",
            url: "/index.php?app=ccs&module=pages&section=pages&id=7",
            data: dataString,
            success: function() {
                $('#postsuccess').html("<b>Post Successful</b>");
            }
        });
        return false; // This is also bad placed
    });
});

and try to combine it all, like:

jQuery(document).ready(function() {

    jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');

    var refreshId = setInterval(function() {
        jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
    },
    30000);

    jQuery(".button").click(function() {
        var dataString = 'tweet=' + tweet;
        //alert (dataString);return false;
        $.ajax({
            type: "POST",
            url: "/index.php?app=ccs&module=pages&section=pages&id=7",
            data: dataString,
            success: function() {
                $('#postsuccess').html("<b>Post Successful</b>");
            }
        });

        return false;
    });
});

if you are not using any other javascript framework, you can replace all jQuery words for the $sign, like:

$(document).ready(function() {

    $('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');

    var refreshId = setInterval(function() {
        $('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
    },
    30000);

    $(".button").click(function() {
        var dataString = 'tweet=' + tweet;
        //alert (dataString); return false;
        $.ajax({
            type: "POST",
            url: "/index.php?app=ccs&module=pages&section=pages&id=7",
            data: dataString,
            success: function() {
                $('#postsuccess').html("<b>Post Successful</b>");
            }
        });

        return false;
    });
});

and your $.ajax method should be

url: "/index.php",
data: { app: 'css', module: 'pages', section: 'pages', id: 7, tweets: tweet },


Try this:

jQuery(document).ready(function() {
    jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
    var refreshId = setInterval(function() {
        jQuery('#tweets').load('/index.php?app=ccs&module=pages&section=pages&id=6');
    }, 30000);
});
jQuery(function() {
    jQuery(".button").click(function() {
        var dataString = 'tweet=' + tweet;
        //alert (dataString);return false;
        $.ajax({
            type: "POST",
            url: "/index.php?app=ccs&module=pages&section=pages&id=7",
            data: dataString,
            success: function() {
                $('#postsuccess').html("<b>Post Successful</b>");
            } // this is where the parse error is
        });
    });
    return false;
});

Sites like jsfiddle.net make indenting easy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜