Voila je code un panel de serveur de jeux sous cake-php j'ai déja fait une bonne partie ( Création sauvegarde du serveur sur des machines distante,Création de l’accès FTP automatique, démarré et arrêt du serveur etc...)
J'ai mis en place une fonctionnalité qui permet de changer de version le serveur ( server.jar ) tout se fait en ajax
Si tout se passe bien j'ai une petite notification qui me dit que le version a bien été changer et que je peut démarrer le serveur.
Hors j'ai bien cette petite notification, la version est bien changer mais j'ai en plus une alerte qui est censé apparaître si il y a un problème voila le code ajax:
[javascript]$('document').ready(function () {
/* AJAX SUBMIT FORMS, AND LISTEN FOR RESPONSE */
// this is the id of the submit button
$("#modpacks").click(function() {
var unique_id = $.gritter.add({
// (string | mandatory) the heading of the notification
title: 'Action serveur',
// (string | mandatory) the text inside the notification
text: 'La version à bien été changer vous pouvez démmarer le serveur !',
// (string | optional) the image to display on the left
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: false,
// (int | optional) the time you want it to be alive for before fading out
time: '',
// (string | optional) the class name you want to apply to that specific message
class_name: 'my-sticky-class'
});
var form = $('#changemodspack');
var url = form.attr('action'); // the script where you handle the form input.
var act = $('#inst_activity');
//show processing on the left
//submit
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success : function(data) {
var unique_id = $.gritter.add({
// (string | mandatory) the heading of the notification
title: 'Action serveur',
// (string | mandatory) the text inside the notification
text: data,
// (string | optional) the image to display on the left
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: false,
// (int | optional) the time you want it to be alive for before fading out
time: '',
// (string | optional) the class name you want to apply to that specific message
class_name: 'my-sticky-class'
});
},
error : function(data) {
alert(data);
}
});
return false; // avoid to execute the actual submit of the form.
});
});
[/javascript]
Et voila le code HTML:
<table class="table table-bordered table-striped">
<tbody><tr>
<td>Version de Minecraft</td>
<td>
<form action="/cubecp/Minecraft/change/37" id="changemodspack" method="post" class="installform">
<div class="input select clearfix"><label for="mod_packs">Version de votre serveur</label><div class="input added"><select name="changemodspack" id="mod_packs">
<option value="7">Craftbukkit 1.7.9</option>
<option value="8">Craftbukkit 1.7.2</option>
<option value="9">mcpc1.4.7</option>
</select></div></div>
</form>
<a href="/cubecp/Minecraft/servers" id="modpacks" class="btn btn-primary">
<i class="fa fa-barcode"></i>
<p>Changer la version</p>
</a>
</td>
</tr>
</tbody></table>
La console java script :POST http://192.168.**.**/cubecp/Minecraft/change/37 500 (Internal Server Error)
jquery-1.9.1.min.js:5
sendjquery-1.9.1.min.js:5
b.extend.ajax
navigation.js:232 (anonymous function)
jquery-1.9.1.min.js:3
b.event.dispatchjquery-1.9.1.min.js:3 v.handle
navigation.js: ligne 232
[javascript] $.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success : function(data) {
var unique_id = $.gritter.add({[/javascript]