我使用Wordpress 3和jQuery 1.4.2。 Firebug告诉我$ .parseJSON不是一个函数,我很难理解为什么。jQuery - parseJSON不是一个函数吗?
任何建议表示赞赏。
$(document).ready(function(){
$('#subscribe_form_submit').click(function(){
function updatePage(theResponse, textStatus, XMLHttpRequest){
theResponse = $.parseJSON(theResponse);
console.log(theResponse);
if(theResponse == "OK!"){
$('#subscribe').fadeOut('fast', function(){
$('#subscribe').html("<br /><h3 style=\"text-align:center;border:1px solid #fff;background-color:#d3eefe;padding:8px;\">Thanks!</h3><br /><br />");
$('#subscribe').fadeIn('slow');
});
}
else{
theResponse = $.parseJSON(theResponse);
console.log(theResponse);
}
}
var theData = $('#subscribe').serialize();
$.ajax({
type: 'GET',
url: 'http://www.foo.com/wp-content/themes/thesis_17/custom/subscribe.php?' + theData,
dataType: 'json',
success: updatePage(),
error: function(xhr, textStatus, errorThrown){
console.log((errorThrown ? errorThrown : xhr.status));
}
})
});
});
查看API文档http://api.jquery.com/jQuery.parseJSON/, – Felix 2010-09-14 14:46:27
第二行最后一行缺少分号。补充说,也许这可以解决问题... – davehauser 2010-09-14 14:46:29