For some reason, AJAX does not work.
JS: (instead of ip.ip.ip.ip there is a normal IP, of course).
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" ></script> <script type="text/javascript"> $(document).ready(function () { var validateStatus = $('#validateStatus'); $('#status').blur(function() { var t = this; validateStatus.removeClass('error').removeClass('success').html('<img src="/view/images/ajax.gif" height="16" width="16" /> update ...'); var td = t.parentNode; var ID_of_TD = td.id; $.ajax({ url: 'http://ip.ip.ip.ip/src/util/ajax.php', data: 'action=setStatus&status=' + t.value + '&id=' + ID_of_TD, dataType: 'json', type: 'post', success: function (j) { if(j.ok){ validateStatus.html('<img src="http://ip.ip.ip.ip/view/images/accept.png"/>').removeClass('error').addClass('success'); } else{ validateStatus.html('<img src="http://ip.ip.ip.ip/view/images/exclamation.png"/> '+j.msg).removeClass('success').addClass('error'); } } }); }); }); </script> HTML
<td id="557144"><input type="text" id="status" name="status" maxlength="30" required /><span id="validateStatus"></span><br/></td> PHP:
(one)
if (@$_REQUEST['action'] == 'setStatus' && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { echo json_encode(setStatus($_REQUEST['status'], $dbh)); exit; } (2)
function setStatus($id, $status, $dbh) { $response = array(); $dao = new UserDao($dbh); if ($dao->setStatusUser($id, $status, $dbh)) { $response = array( 'ok' => true, 'msg' => ""); } else { $response = array( 'ok' => false, 'msg' => "Wrong."); } return $response; } (3)
public function setStatusUser($id, $status){ $stmt = $this->dbh->prepare("UPDATE `vk_users` SET `status`= :status WHERE `vkid`= :id"); $stmt->bindParam(':id', $id, PDO::PARAM_STR, 250); $stmt->bindParam(':status', $status, PDO::PARAM_STR, 250); $stmt->execute(); $count = $stmt->fetchColumn(); return $count; }
/path/to/filefrom the root. - user31688error: function(jqXHR jqXHR, String textStatus, String errorThrown) { ... }( documentation ) and find out what is wrong . - Regent