J'ai du mal à faire fonctionner correctement mon ajax jQuery. Il dirige vers la page PHP pour mettre à jour la base de données, mais ne revient jamais vers le script pour les options de succès ou d'erreur.
Mon code est le suivant :
$(document).ready(function(){
$("form#updatejob").submit(function() {
function textreplace(x) {return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");}
// we want to store the values from the form input box, then send via ajax below
var job = $("#job").attr("value");
var description = $("#description").val();
description.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
var startDate = $("#startDate").attr("value");
var releaseDate = $("#releaseDate").attr("value");
var status = $("#status").attr("value");
$.ajax({
beforeSend:textreplace(description),
type: "POST",
url: "updatedjob.php",
data: "jobID="+ job +"& description="+ description +"& startDate="+ startDate +"& releaseDate="+ releaseDate +"& status="+ status,
success: function(){
$("form#updatejob").hide(function(){$("div.success").fadeIn();});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
return false;
});
});
Et le PHP :
<?php
include("connect.php");
$job = trim($_POST['job']);
$startDate = trim($_POST['startDate']);
$releaseDate = trim($_POST['releaseDate']);
$mysqlstartdate = date('Y-m-d', strtotime($startDate));
$mysqlreleasedate = date('Y-m-d', strtotime($releaseDate));
$description = trim($_POST['description']);
$status = trim($_POST['status']);
$update = "UPDATE jobs SET startDate = '$mysqlstartdate', releaseDate = '$mysqlreleasedate', description = '$description', status = '$status' WHERE jobID = '$job' ";
$rsUpdate = mysql_query($update);
// or die(mysql_error()); mysql_close();
?>