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§ion=pages&id=6');
var refreshId = setInterval(function() {
jQuery('#tweets').load('/index.php?app=ccs&module=pages§ion=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§ion=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§ion=pages&id=6');
var refreshId = setInterval(function() {
jQuery('#tweets').load('/index.php?app=ccs&module=pages§ion=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§ion=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§ion=pages&id=6');
var refreshId = setInterval(function() {
jQuery('#tweets').load('/index.php?app=ccs&module=pages§ion=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§ion=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§ion=pages&id=6');
var refreshId = setInterval(function() {
$('#tweets').load('/index.php?app=ccs&module=pages§ion=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§ion=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§ion=pages&id=6');
var refreshId = setInterval(function() {
jQuery('#tweets').load('/index.php?app=ccs&module=pages§ion=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§ion=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.
精彩评论