Fuad Pashayev
Fuad Pashayev

Reputation: 75

Uncaught TypeError: Cannot read property 'split' of undefined in jquery call back function

I have very big trouble with $.post() callback. This function return some value, but when I look for its type (back.type) it returns "defined" and I have error loop that increase every second and it cause problems.

function upMessage() {
  var id = $(".id").val();
  var data = "id=" + id;
  $.post("ajax/upMessage.php", {
    id: id
  }, function(back) {
    back = back.split(",");
    for (var i = 0; i <= (parseInt(back.length)) + 1; i++) {
      var backing = back[i];
      backing = backing.split("*");
      if (backing != "he," && backing != undefined && backing != "") {
        var id = backing[0];
        var oxu = backing[1];
        if (oxu == "he") {
          oxu = "<i class=\"fa fa-check\" style=\"color:#2B85DB;margin-right:-7px\"></i><i class=\"fa fa-check\" style=\"color:#2B85DB;\"></i>";
        } else {
          oxu = "<i class=\"fa fa-check\" style=\"margin-right:-7px\"></i><i class=\"fa fa-check\"></i>";
        }
        $("span#r" + id + ".i").html(oxu);
      }
    }
  });
}
setInterval(upMessage, 700);

I have error loop in page. For example. http://masters.az login:leo pass:12345

Upvotes: 2

Views: 9119

Answers (1)

Damask
Damask

Reputation: 1254

  1. Put split after your check if (backing != "he," && backing !=...
  2. Avoid type changing in your code. "backing" was a string then it is an array. Use different variables.
  3. Show error message you get.

Upvotes: 2

Related Questions