Ajax函数使得javascript的其余部分被忽略

时间:2018-05-01 21:27:41

标签: javascript ajax web

我需要帮助解决我遇到的问题而且无法解决。我在网络开发领域相对较新,这是我真正感兴趣的东西,所以我想要擅长它。我正在尝试在Javascript中为我的网站实现ajax功能。当我删除 showDetails() 函数时,其余的Javascript运行完美。但是当我实现 showDetails() 函数时,脚本中的其他所有内容都会被忽略,就像它是空的一样,里面只有ajax函数。如何才能获得其他代码以获得认可?我做错了吗?

这是我的代码:

function showRegUsr() {

  if ($('#regUsr').is(':hidden')) {
    $("#regUsr").slideDown();
    $("#joinReq").slideUp();
    $("#searchBy").slideUp();
    document.getElementById("tabRegUsr").style.cursor = 'default';
    document.getElementById("tabJoinReq").style.cursor = 'pointer';
    document.getElementById("tabSearchBy").style.cursor = 'pointer';
  }
}

function showJoinReq() {

  if ($('#joinReq').is(':hidden')) {
    $("#joinReq").slideDown();
    $("#regUsr").slideUp();
    $("#searchBy").slideUp();
    document.getElementById("tabJoinReq").style.cursor = 'default';
    document.getElementById("tabSearchBy").style.cursor = 'pointer';
    document.getElementById("tabRegUsr").style.cursor = 'pointer';
  }
}

function showSearch() {

  if ($('#searchBy').is(':hidden')) {
    $("#searchBy").slideDown();
    $("#joinReq").slideUp();
    $("#regUsr").slideUp();
    document.getElementById("tabSearchBy").style.cursor = 'default';
    document.getElementById("tabJoinReq").style.cursor = 'pointer';
    document.getElementById("tabRegUsr").style.cursor = 'pointer';
  }
}



function showAll() {
  window.location.href = 'notes.php';
  //$("#searchAll").style.display = 'none';
}

window.onload = function() {
  document.getElementById("joinReq").style.display = 'none';
  document.getElementById("searchBy").style.display = 'none';
  document.getElementById("moreTab").style.display = 'none';
  document.getElementById("tabRegUsr").style.cursor = 'default';
  document.getElementById("tabJoinReq").style.cursor = 'pointer';
  document.getElementById("tabSearchBy").style.cursor = 'pointer';
};

function showDetails() {
  var idofclicked = (this.id);

  if ((idofclicked) != "" && (idofclicked) != "hide") {
    $('#moreTab').slideDown();
    $('#pinakas').slideUp();

  }
  if ((idofclicked) == "hide") {
    $('#moreTab').slideUp();
    $('#pinakas').slideDown();

  }

  $.ajax({
    type: 'POST',
    url: 'usersNewFunctions.php',
    data: 'func=showDetails&evID=' + idofclicked,
    success: function(msg) {
      var response = msg.split(';', 8);
      var var1 = response[0];
      var var2 = response[1];
      var var3 = response[2];
      var var4 = response[3];
      var var5 = response[4];
      var var6 = response[5];
      var var7 = response[6];
      var var8 = response[7];

      var var9 = "";

      if (var5 == 3) {
        var9 = "Admin";
      } else if (var5 == 2) {
        var9 = "Team Member";
      } else if (var5 == 1) {
        var9 = "Registered Guest";
      } else if (var5 == 0) {
        var9 = "Unregistered User";
      }

      document.getElementById("name").innerHTML = "Name: " + var1;
      document.getElementById("surname").innerHTML = "Surname: " + var2;
      document.getElementById("username").innerHTML = "Username: " + var3;
      document.getElementById("email").innerHTML = "Email: " + var4;
      document.getElementById("type").innerHTML = "Type: " + var9;
      document.getElementById("created_on").innerHTML = "Joined on: " + var6;
      document.getElementById("newsletter").innerHTML = "Newsletter: " + var7;
      document.getElementById("image").innerHTML = var8;
    }
  });
});

0 个答案:

没有答案