【发布时间】:2018-08-29 09:55:09
【问题描述】:
我是 ajax 和 jQuery 的新手,我刚刚为我最后一年的项目做了这个 我在向 java 脚本添加方法时遇到了一些问题,这是我的 ajax 脚本:
$(document).ready(function() {
$('#campus_feed').html('<br><br><br><br><br><br><br><br><br><br><br><br>
<center><img src="loader.gif"></center>');
fetch_data();
setInterval(fetch_data, 5000); // 5 seconds
// FETCHING DATA
function fetch_data()
{
var action = "fetch";
$.ajax({
url:"fetch_action.php",
method:"POST",
data:{action:action},
success:function(data)
{
$('#campus_feed').html(data);
}
})
}
/////////////////////////////////////////////////////
$("#profile_nav").click(function profile_dflt() {
$('#content').html('<br><br><br><br><br><br><br><br><br><br><br><br><img src="loader.gif">');
$.ajax({
url: "profile.php",
method:"POST",
success: function(result)
{
$("#profile_nav").css({"background-color":"#4CAF50"});
$("#nofication_nav").removeAttr("style");
$("#chat_nav").removeAttr("style");
$("#forum_nav").removeAttr("style");
$("#post_nav").removeAttr("style");
$("#content").html(result);
}
});
});
////////////////////////////////////////////////////////////
$("#nofication_nav").click(function(){
$.ajax({
url: "nofication.php",
method:"POST",
success: function(result)
{
$("#nofication_nav").css({"background-color":"#CCCC00"});
$("#profile_nav").removeAttr("style");
$("#chat_nav").removeAttr("style");
$("#forum_nav").removeAttr("style");
$("#post_nav").removeAttr("style");
$("#content").html(result);
}
});
});
///////////////////////////////////////////////////////////
$("#chat_nav").click(function(){
$.ajax({
url: "chat.php",
method:"POST",
success: function(result)
{
$("#chat_nav").css({"background-color":"#008CBA"});
$("#nofication_nav").removeAttr("style");
$("#profile_nav").removeAttr("style");
$("#forum_nav").removeAttr("style");
$("#post_nav").removeAttr("style");
$("#content").html(result);
}
});
});
///////////////////////////////////////////////////////
$("#forum_nav").click(function(){
$.ajax({
url: "forum.php",
method:"POST",
success: function(result)
{
$("#forum_nav").css({"background-color":"#FF00FF"});
$("#nofication_nav").removeAttr("style");
$("#chat_nav").removeAttr("style");
$("#profile_nav").removeAttr("style");
$("#post_nav").removeAttr("style");
$("#content").html(result);
}
});
});
///////////////////////////////////////////////////////
$("#post_nav").click(function(){
$.ajax({
url: "post.php",
method:"POST",
success: function(result)
{
$("#post_nav").css({"background-color":"#F44336"});
$("#nofication_nav").removeAttr("style");
$("#chat_nav").removeAttr("style");
$("#forum_nav").removeAttr("style");
$("#profile_nav").removeAttr("style");
$("#content").html(result);
}
});
});
});
当我添加SETINTERVAL()方法和其他额外方法时,它显示警告消息,我不知道为什么显示此警告,我认为我在语法声明中犯了错误,请帮我解决这个
【问题讨论】:
标签: php jquery html ajax debugging