F-y-o-d-o-r
2/13/2018 - 10:09 AM

jquery - ajax

jquery - ajax

select: function (value) {
      var ajaxSetting = {
        method: 'post',//homework: in url "form_update.php" - data no need. function - where to put
        url: 'controller.php',//?hook=search?ddd - get
        data: "hook=select&search=" + value,//proizvolnie names -- post
        success: function (data) {
          //alert(data);
          var data_json = JSON.parse(data);
          for (var i in data_json) {
            if (i === "error") {
              $(".span_error").html(data_json[i]);
            }
            if (i === "select") {
              var str_json = "";
              for (var j in data_json[i]) {
                str_json += "<tr><td>" + data_json[i][j]['name'] + "</td><td>" + data_json[i][j]['address'] + "</td><td>" + data_json[i][j]['email'] + "</td><td>" + data_json[i][j]['phone'] + "</td><td class='td_img'>" + data_json[i][j]['image'] + "</td></tr>";
              }
              str_json = "<table>" + str_json + "</table>";
              $(".table").html(str_json);
              $('.td_img').css('visibility', 'hidden');
            }
          }
        }
      };
      $.ajax(ajaxSetting);//вывод через аякс
    },
    
    
    
    
    ------------------------
    case 'select':
      $value = mysqli_real_escape_string($obj->link_db, $_POST['search']);
      if ($obj->validate($value)) {
        $arr_data['error'] = $obj->validate($value);
      } else {
        $obj->query = "select name, address, email, phone, image from users where name like '%$value%' or address like '%$value%' or email like '%$value%' or phone like '%$value%'";
        $obj->DB_query();
        $arr_data['select'] = $obj->row_db;
      }
      break;